PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 15, 2022

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

 April 15, 2022     html, iframe, java, selenium, webdriver     No comments   

Issue

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&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>

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)


Solution

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')]


Answered By - Max Daroshchanka
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing