I want to operate on an element on a website, which is inside an iFrame and further inside a document tag. How to do that?
Are you referring to a structure like this?
<iframe id="FRAMENAME"> #document <html> CODE.... </html>
Yes. How to work with these?
Have you tried using XPath?
Yes. I did. I tried to copy the XPath from the webpage and use it, but due to this tag, it is not pointing on the correct element
Ok got it. You need to switch to particular iFrame before accessing its elements. Simply add a switchTo like this:
will try it out
Sure Tim. Please let me know if it works for you
@rishabhps It didnt work
I am getting a NoSuchElementException
You might want to insert a wait for your IFrame and element to load.
You can also use
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.name("FRAMENAME")));
It will wait until the IFrame becomes available
Great. It worked.
Thanks a lot @rishabhps
Is their any other way to do this? Just curious
At the moment, Selenium does not have any other ways to work with
Hence you need to switch to specific one, to work with them.
You can also refer Selenium Focus Issues And How to Solve Them to learn more
ok. thanks for the help