簡體   English   中英

如何訪問沒有 ID、名稱或 class 的 iframe

[英]How do I access the iframe that does not have an id, name or class

我有以下 iframe:


<iframe _ngcontent-oyp-c7="" allow="fullscreen" allowfullscreen="" mozallowfullscreen="" scrolling="yes" webkitallowfullscreen="" src="https://launch.spribegaming.com/games/launch/aviator?user=164291&amp;token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJQdW50ZXJJZCI6IjE2NDI5MSIsIm5iZiI6MTY0MzcyMjU5NCwiZXhwIjoxNjQzNzQ0MTk0LCJpYXQiOjE2NDM3MjI1OTR9.7st61IJ2K4nOHIhezeg9exDUk-mh0t21e73Dq5QQdbY&amp;lang=EN&amp;currency=ZAR&amp;operator=hollywoodbets&amp;return_url=https://new.hollywoodbets.net" frameborder="0"></iframe>

我如何獲取它的元素,因為它沒有 ID、名稱或 class。 還有另一種訪問方式嗎? 它是一個單一的 iframe,所以我不能通過像switchTo.frame(int frame number)這樣的索引來調用它

driver.switchTo.frame接受網絡元素 object 參數。

frame_element = driver.find_element(...)
driver.switchTo.frame(frame_element)

在這種情況下,為了定位 iframe,我建議使用 XPATH。

對於單個 iframe 只需

//iframe

對於多個 iframe,您必須找到一些獨特的屬性過濾器

//iframe[@_ngcontent-oyp-c7]

或者

//iframe[contains(@src, 'spribegaming.com/games')]

甚至將條件與或/和xpath 運算符結合起來:

//iframe[(@scrolling='yes') or (@allow='fullscreen')]

暫無
暫無

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

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