Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expedite switching between iFrames in Selenium Webdriver with Java code?

For Selenium WebDriver: I'm using Eclipse IDE and Java code

Application under testing: Built in C#

My script needs to switch between frames and perform some actions. This needs to be done quite frequently. The problem is that script execution gets very slow (around 20 seconds delay) whenever switching statements are executed. The frame hierarchy is as follows:

1 parent frame: MainFrame
3 child frames: left, center and right

The set of statements for any one switch looks something like:

driver.switchTo().defaultContent();
driver.switchTo().frame("mainFrame"); //switching to parent frame. This statement causes the delay
driver.switchTo().frame("left"); //switching to left frame

Please suggest if there is a way to avoid this delay.

like image 351
Mohit Avatar asked Sep 11 '26 00:09

Mohit


1 Answers

You can store a frame as an element variable first and then switch to it.

Here is an example:

var frameExample = driver.FindElement(By.className("myFrame"));
driver.switchTo().frame(frameExample);

So essentially, you store frames in element variables and switch when needed, it will help with performance issues.

like image 104
Naughty Ninja Avatar answered Sep 13 '26 13:09

Naughty Ninja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!