Switching between frames is very slow

1,468 views
Skip to first unread message

Louise

unread,
Nov 17, 2015, 12:43:29 PM11/17/15
to webdriver
Hi, I just started using Selenium WebDriver and found that switching between frames takes quite a long time, much more than switching window.
Am I doing anything wrong, or is that just how it is?
 
Information:
  • I have a website with multiple iframes, and it works switching between them, it just takes a long time.
  • The frames are available as soon as the page is loaded, but the content within the frames can be changed by user interactions, so it shouldn't be a problem with not finding the frame?
  • Code: webdriver.switchTo().frame("main");

darrell

unread,
Nov 18, 2015, 12:42:03 PM11/18/15
to webdriver
The webdriver.switchTo().frame() method can take a name or an id. It would have to search the DOM (Document Object Model) for the name or id. You can have multiple things on a page with the same name attribute. So using id attributes tend to be faster. However, if the computer running the browser is slow and/or there are a lot of attributes in the DOM, it could take a while to switch frames.

There is also a webdriver.switchTo().frame() method which takes an index. So if you know it is frame number 1 you can just use webdriver.switchTo().frame(1). But if the order of the frames may change this is not helpful. You can also use a WebElement to switch frames. So sometimes the webdriver.findElement() method will find the frame faster and switching to this WebElement will be faster.

This is really getting more into optimizing your code to be faster.
Reply all
Reply to author
Forward
0 new messages