In this image I want to click view buttons as one by one that view buttons have same names. I am using list concept that is not working.
-
Can you share the DOM code from the iFrame element to the View elements?– João FariasCommented Mar 25, 2019 at 13:13
-
Anijith, as a new contributor, you may not know, but it's common to mark as "Accepted" answers that fully satisfy your questions. It both motivates the contributors and express that you already have your answer.– João FariasCommented Mar 25, 2019 at 18:00
1 Answer
Selenium provides two methods to deal with iFrames.
You can search for a iFrame with id IFRAME_ID
driver.switchTo().frame(IFRAME_ID)
And you can return to the context of the root element:
driver.switchTo().defaultContent()
Of course, you can chain iFrames:
driver.switchTo().frame(IFRAME_ID1).switchTo().frame(IFRAME_ID2)
Meaning you will enter in the iFrame with ID IFRAME_ID2 which is inside the IFRAME_ID1.
If they were siblings, you would need to return to the default context:
driver.switchTo().frame(IFRAME_ID1);
driver.switchTo().defaultContent();
driver.switchTo().frame(IFRAME_ID2);
After switching to a iFrame, you can use WebDriver and WebElements as if the only the DOM branches inside the iFrame exist.