簡體   English   中英

如何在沒有 id 的情況下找到 IFRAMES 及其元素?

[英]How to find IFRAMES and their elements inside without the id?

詳細信息:該機器人有 function 用於填寫表單中的回復,但該表單位於頁面上的 iframe 中。 但是,它沒有標識(名稱、ID、class 等),只有來源 (scr)。

我試圖找到替代方案,但找不到。 有人有什么想法嗎?

想法是使用 PLAYWRIGHT 庫將數據插入 iframe 中的表單

如果您的頁面只有一個沒有名稱的框架,則可以使用以下方法:

page.frame_locator("iframe").locator("#myfield").click()
page.frame_locator("iframe").locator("#myfield").fill("hello world")

如果您的頁面有多個帶有名稱的框架,您將不得不求助於 .nth() ,這並不好:

page.frame_locator("iframe >> nth=0").locator("#myfield").click()    page.frame_locator("iframe >> nth=0").locator("#myfield").fill("aaa")
page.frame_locator("iframe >> nth=1").locator("#myfield").click()
page.frame_locator("iframe >> nth=1").locator("#myfield").fill("bbb")
page.frame_locator("iframe >> nth=2").locator("#myfield").click()
page.frame_locator("iframe >> nth=2").locator("#myfield").fill("ccc")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM