Selenium gets very slow at switching between iframe

Viewed 2129

I am passing through the same problem (not resolved, BTW) on this Java question, but at C#: Testcase running very slow after opening new window with iFrame

The iframe I am switching to:

<iframe id="iframeXYZ" width="100%" height="2280px" frameborder="0" src="/Pages/Abc.html">
</iframe>

Code to select this iframe:

    var frameXYZ = driver.FindElement(By.Id("IdOfMyFrame"));
    driver.SwitchTo().Frame(frameXYZ);
        //I do my stuff here, then return to the main frame
    driver.SwitchTo().DefaultContent(); 

The class does not have any Thread.Sleep, nor even explicit/implicit waits.

I ran into this information, but even using the ID of the iframe, it did not help:

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.

Font: https://grokbase.com/t/gg/webdriver/15bh2n599f/switching-between-frames-is-very-slow

I would like to know if this problem is something related to Chrome browser itself, and if it does not have a final solution.

0 Answers
Related