0

I have a .jsp page that I'm trying to grab the web elements from and perform click and input functions upon. After trial and error of trying to identify these web elements on the jsp page, I noticed that the page contains "iframes". I've looked up resources to be able to navigate through iframes by name, and also navigating iframes by index here

https://www.guru99.com/handling-iframes-selenium.html 

However, I feel I have a special case since all the iframes I'm dealing with do not have an element ID or Name. Also, the iframe I need to navigate to is nested within other iframes.

Because as far as I know, I'm limited to using switchTo().frame(index)

since none of the iframes are named, I've already tried webDriver.switchTo().frame(index);

but because I'm dealing with nested iframes, I'm unsure that I'm getting to where I need to be. I've tried something like

webDriver.switchTo().frame(0);
webDriver.switchTo().frame(1);
webDriver.switchTo().frame(2);
webDriver.switchTo().frame(3);

to see how far I can drill down before I get an exception. It's just hard as I'm also unable to identify which iframe I'm currently in. Perhaps I need to create an object of the current iframe, and drill down that way?

The code looks something a little like this...

<iframe height="708px" width="100%" marginheight="0" frameborder="0" scrolling="auto" src="..."></iframe>
...
<iframe height="708px" width="100%" marginheight="0" frameborder="0" scrolling="auto" src="..."></iframe>
...
...<iframe onload="..." height="100%" width="100%" marginheight="0" frameborder="0" scrolling="no" src="..."></iframe>
...
... ...<iframe onload="..." height="100%" width="100%" marginheight="0" frameborder="0" scrolling="YES" src="..."></iframe> 

This is where I need to be

I would expect to be able to successfully grab the web elements inside of the iframe that I'm dealing with, but I've been unsuccessful so far as I'm not sure how to navigate through these iframes. I'm assuming that

webDriver.switchTo().frame(index);

is my only option since the iframes are unnamed and have no element ID. But that's why I'm here.

Austin Duran
  • 83
  • 1
  • 1
  • 9
  • Most likely these iframes have different links in the attribute `src="..."`, so you can identify them using that link (or a part of it that is unique to a given link).You can use a locator like this: `finfElement(By.xpath("//iframe[contains(@src,'some unique part of link')]")` – krokodilko Jun 22 '19 at 23:36
  • Have you checked [this](https://stackoverflow.com/questions/55536851/is-there-a-way-to-search-webelement-on-a-main-window-first-if-not-found-then-s/55537186#55537186) – supputuri Jun 23 '19 at 01:07
  • @krokodilko I just tried something like this... webDriver.switchTo().frame(webDriver.findElement(By.xpath(".//iframe[@src='/ody/serv/Odyssey?FromPage=n&ToPage=/jsp/comm/Comm.jsp']"))) and still no luck. I'm curious if trying to do this on a .jsp page would have something to do with it? – Austin Duran Jun 26 '19 at 16:47

2 Answers2

1

Found an answer to my problem.

Be aware of the fact that each iframe starts at the index 0.

Therefore if you have nested iframes without name or id -- something like this

(Frame C) is nested in (Frame B) which is nested in (Frame A)

  • Frame A
  • ---Frame B
  • ------Frame C

you would try something like this

    driver.switchTo().frame(0)
    driver.switchTo().frame(0)
    driver.switchTo().frame(0)

in order to get to "Frame C"

Austin Duran
  • 83
  • 1
  • 1
  • 9
0

Bro, as you limited with index number , why don't you have call with your dev team and ask to set frame name on request basis . We did same in similar cases

bheemesh
  • 1
  • 2