简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM