selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Executing Javascript in Safari 8 creates new frame

Open para-selenium-bugs opened this issue 11 years ago • 1 comments

Executing any Javascript using SafariDriver on Safari 8 will create a new frame. The frame is not visible, and is a reference to the current window.

Reproduced with: Selenium 2.45 Safari 8.0.3 Mac 10.10.2

The following code will succeed, even though www.example.com has no frames.

import org.junit.*;
import org.openqa.selenium.safari.*;

public class SafariTest {
    @Test
    public void test() throws Throwable {
        SafariDriver driver = new SafariDriver();
        driver.get("http://www.example.com");

        // comment out this line to cause test to fail
        driver.executeScript("return 0;");

         // this step should fail because www.example.com has no frames
        driver.switchTo().frame(0);

        // as is the test will pass, which is unexpected behavior
    }
}

Debugging from within Safari shows that window.frames.length == 1. window.frames[0] seems to be a copy of the parent window.

This causes issues when attempting to recursively iterate frames. If any Javascript is executed after switching to a child frame and before checking for more frames, iteration will continue forever as WebDriver creates new frames on each iteration.

para-selenium-bugs avatar May 13 '15 01:05 para-selenium-bugs

Should be fixed by 8380cd6a60cf4bba4265337c5b087748343e4b27.

Big thanks to @juangj and @jleyba for the fix, apologies to @juangj for ignoring #507 for so long, thanks @para-selenium-bugs for this reminder.

sevaseva avatar May 17 '15 05:05 sevaseva