Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox fails to switch out of iframe #205

Closed
iam-mholle opened this issue May 9, 2019 · 3 comments · Fixed by #207
Closed

Firefox fails to switch out of iframe #205

iam-mholle opened this issue May 9, 2019 · 3 comments · Fixed by #207
Labels

Comments

@iam-mholle
Copy link

iam-mholle commented May 9, 2019

We have discovered that when switching into an iframe using Firefox, the scope gets set to the iframe scope and does not switch back (like it does in e.g. Chrome) when trying to select elements in the outer scope. They can't be found.

Some digging revealed that Firefox Marionette does not switch back to the DefaultContent when switching out of an iframe using SwitchTo().Window(...). This issue is known to Mozilla and a bug report can be found here. Since it appears like it will not be fixed by Mozilla in the near future, have you considered adding a fix to your library?

It would seem that the issue could be fixed by changing SeleniumWindowManager.SwitchToWindow(...) to the following:

public void SwitchToWindow(string windowName)
{
    if (LastKnownWindowHandle != windowName || SwitchedToAFrame)
    {
        _webDriver.SwitchTo()
                  .Window(windowName);

        // Fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1305822 
        if (_webDriver is FirefoxDriver)
        {
            _webDriver.SwitchTo()
                      .DefaultContent();
        }

        LastKnownWindowHandle = windowName;
    }

    _switchedToFrame = null;
    _switchedToFrameElement = null;
}

This would make sure that the context resets to the DefaultContent like it should do, according to the W3C WebDriver specification, and does not have any side effects.

@obstar
Copy link
Collaborator

obstar commented May 9, 2019

I will take a look, thanks.

@iam-mholle
Copy link
Author

This also affects FrameFinder.FrameContentsMatch(...), and could be fixed the same way:

private bool FrameContentsMatch(IWebElement e,
                                string locator,
                                Options options)
{
    var currentHandle = _selenium.CurrentWindowHandle;
    try
    {
        var frame = _seleniumWindowManager.SwitchToFrame(e);
        return
            frame.Title == locator ||
            frame.FindElements(By.XPath($".//h1[{_xPath.IsText(locator, options)}]"))
                 .Any();
    }
    finally
    {
        _selenium.SwitchTo()
                 .Window(currentHandle);

        // Fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1305822 
        if (_selenium is FirefoxDriver)
        {
            _selenium.SwitchTo()
                     .DefaultContent();
        }
    }
}

@iam-mholle
Copy link
Author

Hi @obstar,
just wondering if there are any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants