I am using java with WebDriver.I have to switch between two frames. I have recorded the test case in selenium IDE and in that I got the values as selectFrame relative=top select Frame=middle Frame
But there is a problem it is not able to recognize the relative=top and middleFrame. How can I solve this problem in Selenium WebDriver with Java?
Another way to switch between frames in selenium is to pass the WebElement to the switchTo() command. Here the primary step is to find the iframe element and then pass it to the switch method.
To move back to the parent frame, you can either use switchTo(). parentFrame() or if you want to get back to the main (or most parent) frame, you can use switchTo(). defaultContent(); driver.
Switching between different frames is done using the SwitchTo() command for frames. The SwitchTo frame command is used to switch to the intended frame (or iFrame). Frame id, frame name, and web element locator are used with the SwitchTo command for switching to the intended frame.
To work with different nested iframes, we can use the method switchTo() to switch the frames using Index, Name, or Id & Web Element. Moreover, you can switch to immediate parent iframe using method switchTo(). parentFrame(). You can switch to the main web page from child iframe using method switchTo().
WebDriver's driver.switchTo().frame()
method takes one of the three possible arguments:
A number.
Select a frame by its (zero-based) index. That is, if a page has three frames, the first frame would be at index
0
, the second at index1
and the third at index2
. Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.
A name or ID.
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
A previously found WebElement
.
Select a frame using its previously located WebElement.
Get the frame by it's id/name or locate it by driver.findElement()
and you'll be good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With