Reputation: 37
I have the following 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>
How do I get its element as it doesn't have an Id, name or class. As there another way to access it? It a single iframe, so I cannot call it by index like switchTo.frame(int frame number)
Upvotes: 0
Views: 893
Reputation: 2968
driver.switchTo.frame
accepts web-element object argument too.
frame_element = driver.find_element(...)
driver.switchTo.frame(frame_element)
For locating the iframe in this case I suggest using XPATH.
For a single iframe just
//iframe
For multiple iframes you have to find some unique attributes filter
//iframe[@_ngcontent-oyp-c7]
or
//iframe[contains(@src, 'spribegaming.com/games')]
or even combine conditions with or/and xpath operators:
//iframe[(@scrolling='yes') or (@allow='fullscreen')]
Upvotes: 1