最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python Playwright 文本框操作技巧

 更新時間:2023年05月16日 10:59:42   作者:田辛 | 田豆芽  
這篇文章主要介紹了Python Playwright 文本框操作技巧,包括如何獲得文本框的值,以及向文本框中添加單行和多行文本,本文結(jié)合實例代碼給大家介紹的非常詳細,需要的朋友可以參考下

在本文中,將詳細介紹Playwright的文本框操作, 包括如何獲得文本框的值, 以及向文本框中添加單行和多行文本。

田辛老師將用網(wǎng)上的一個測試畫面來進行說明:

URL:https://demoqa.com/text-box

F12 查找網(wǎng)站源碼,我們可以知道這四個Textbox元素的元素id。

  • userName
  • userEmail
  • currentAddress
  • permanentAddress

1 填充單行文本

我們可以使用頁面對象的 page.locator() 方法來查找元素,并使用 fill() 方法來輸入內(nèi)容。

# 輸入Full Name
page.locator("#userName").fill("Your Name")

2 填充多行文本

對于多行文本來說, 方法和單行文本一致。 只不過需要通過\n來進行分行。

# 填充地址
page.locator("#currentAddress").fill("Your current address\nYour current address 2\nYour current address 3")

3 獲取文本框的值

使用input_value()方法獲得文本框的值。

print(page.locator("#userName").input_value()) 
print(page.locator("#currentAddress").input_value())

4 完整代碼

老規(guī)矩, 完整代碼示例:

from playwright.sync_api import Playwright, sync_playwright, expect 
def run(playwright: Playwright) -> None: 
	browser = playwright.chromium.launch(headless=False) 
	context = browser.new_context() 
	# Open new page 
	page = context.new_page() 
	# Go to https://demoqa.com/text-box 
	page.goto("https://demoqa.com/text-box") 
	# Fill #userName 
	page.locator("#userName").fill("Your Name") 
	# Fill #userEmail 
	page.locator("#userEmail").fill("your.name@yourdomain.com") 
	# Fill #currentAddress 
	page.locator("#currentAddress").fill("Your current address\nYour current address 2\nYour current address 3") 
	# Fill #permanentAddress 
	page.locator("#permanentAddress").fill("Your permanent address 1\nYour permanent address 2\nYour permanent address 3") 
	# --------------------- 
	context.close() 
	browser.close() 
with sync_playwright() as playwright: 
	run(playwright)

執(zhí)行結(jié)果:

到此這篇關于Python Playwright 文本框操作的文章就介紹到這了,更多相關Python Playwright 文本框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

麦盖提县| 湖北省| 黎平县| 昔阳县| 读书| 潼南县| 四川省| 安陆市| 宝坻区| 长丰县| 新巴尔虎右旗| 灵石县| 错那县| 花莲县| 邮箱| 榆树市| 夹江县| 伊金霍洛旗| 故城县| 会泽县| 彭阳县| 禹州市| 遵化市| 广西| 波密县| 长垣县| 密云县| 东乌珠穆沁旗| 周至县| 牙克石市| 河池市| 横山县| 张家川| 栾川县| 东台市| 宁波市| 连城县| 清水河县| 黄山市| 密云县| 习水县|