最新国产好看的视频,伊人天堂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é)果:

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

相關(guān)文章

最新評論

永清县| 伊春市| 万年县| 察隅县| 门头沟区| 基隆市| 黄石市| 大丰市| 南陵县| 南昌县| 威信县| 深州市| 白山市| 新巴尔虎左旗| 综艺| 运城市| 西安市| 当雄县| 水城县| 抚顺市| 偃师市| 明光市| 拜城县| 叶城县| 瑞安市| 揭西县| 区。| 堆龙德庆县| 云安县| 鸡泽县| 濮阳县| 肃北| 彰化县| 新乐市| 辽宁省| 威远县| 新龙县| 青神县| 通道| 清原| 广元市|