![](/img/trans.png)
[英]How do I access elements having the same id, name, class etc. in Selenium
[英]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&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJQdW50ZXJJZCI6IjE2NDI5MSIsIm5iZiI6MTY0MzcyMjU5NCwiZXhwIjoxNjQzNzQ0MTk0LCJpYXQiOjE2NDM3MjI1OTR9.7st61IJ2K4nOHIhezeg9exDUk-mh0t21e73Dq5QQdbY&lang=EN&currency=ZAR&operator=hollywoodbets&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.