Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
216 views
by The go-to Tester (344 points)
retagged by
How can we switch to a frame using Selenium in Java

1 Answer

0 like 0 dislike
by The go-to Tester (473 points)
selected by
 
Best answer

1) First of all , you have to check the element which you want to automate is in the tag <iframe>. If the element is in tag <iframe> then you can follow the steps:

First of all take the index of all the frames present in your current open browser tab. And then use the method driver.switchTo().frame() which will take index of your targeted frame and then will switch control to the targeted frame

 

2) Now if your element is not in tag <iframe> then it means it is simple popup window and you can select that element by following way

2.1) if there are multiple popupwindow open then use follwoing steps

1st take the window id using 

main browser window id you can take using mehtod driver.getwindowhandle();

and remaining window (popup windows) ID take using method driver.getwindowhandles();

Now use the FOR LOOP and check the presence of your element in popup window one by one.

2.2) if there is single popup then means alert box then you can your 

      driver.alert() method 

by The go-to Tester (181 points)
for your answer # 2.2, it will be driver.switchTo().alert()


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...