selenium icon indicating copy to clipboard operation
selenium copied to clipboard

WebDriver v3.7.0 C# Firefox "missing handle parameter" for popup windows

Open AndyUM357 opened this issue 9 years ago • 46 comments

OS: Windows Selenium Version: 3.7.0 Browser: RemoteWebDriver using Firefox v56.0.2 (or any recent Firefox) I am using GeckoDriver 0.19.1

Seems like this might be a C# binding issue in dotnet/src/webdriver/Remote/RemoteTargetLocator.cs where the SwitchTo().Window command is no longer transmitting the proper information expected by geckodriver?

The code below results in an Exception "Missing 'handle' parameter" when switching to the popup.

However, the test passes with Firefox 52.0.2, geckodriver 0.15.0, and WebDriver 3.3.x.

Steps to reproduce -

Here's some HTML with a popup link: (test.html)

<HTML>
 <HEAD><TITLE>Firefox Popup Test Case</TITLE></HEAD>
 <BODY>
  <H1>Firefox Popup Test Case</H1>
   <A id="link" onClick="javascript:window.open('http://www.google.com', 'google');">
    Google Popup Link
   </A>
 </BODY>
</HTML>

Here's some C# code with NuGets of Selenium.WebDriver v3.7.0 and NUnit 3.7.0:

using System;
using NUnit.Framework;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium;
using System.Collections.ObjectModel;
using System.Linq;
using System.Collections.Generic;

namespace WebDriverTestProject
{
    /// <summary>
    /// 
    /// </summary>
    [TestFixture]
    public class UnitTest1
    {
        /// <summary>
        /// 
        /// </summary>
        [Test]
        public void TestMethod()
        {
            IWebDriver webdriver = null;
            try
            {
                DesiredCapabilities dc = DesiredCapabilities.Firefox();
                webdriver = new RemoteWebDriver(new Uri("http://hub:4444/wd/hub"), dc);

                // Popup page
                webdriver.Navigate().GoToUrl("http://webpage/test.html");

                ReadOnlyCollection<string> previousHandles = webdriver.WindowHandles;
                Console.WriteLine("Previous Popup count: " + previousHandles.Count);

                // Trigger popup
                webdriver.FindElement(By.Id("link")).Click();

                // Wait for popup
                do
                {
                    Console.WriteLine("Waiting for popup...");
                    System.Threading.Thread.Sleep(2000);
                } while (previousHandles.Count == webdriver.WindowHandles.Count);

                // Find the popup handle
                ReadOnlyCollection<string> currentHandles = webdriver.WindowHandles;
                IEnumerable<string> popupWindow = currentHandles.Except(previousHandles);
                Console.WriteLine("Popup is here! " + popupWindow.First());

                // Switch to window ====>>>> This is the line in error <<<<====
                webdriver.SwitchTo().Window(popupWindow.First());

                // Validate Google site
                System.Threading.Thread.Sleep(5000);
                Assert.True(webdriver.FindElements(By.CssSelector("input[name='q']")).Count > 0, "Could not find Google search field");
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("==EXCEPTION== " + e + "\n" + e.StackTrace);
                Assert.Fail(e.Message);
            }
            finally
            {
                webdriver.Quit();
            }
        }
    }
}

AndyUM357 avatar Nov 16 '17 14:11 AndyUM357

Issue still present with Selenium C# v3.8.0, Firefox 57.0.2, and GeckoDriver 0.19.1

AndyUM357 avatar Dec 12 '17 19:12 AndyUM357

This is an issue which I'm experiencing when I run test on SauceLabs, so probably a remote webdriver issue. Running locally with Selenium 3.8.1, Firefox 58 and GeckoDriver 0.19.1, just works fine, but the same setup does not works on SauceLabs.

DavidGangel avatar Jan 31 '18 15:01 DavidGangel

Hitting this with Selenium python 3.8.0, Firefox 58, Geckodriver 0.18.0. Remote webdriver only. Runs great locally, fails on browserstack. Firefox only.

jersmo avatar Feb 02 '18 19:02 jersmo

I am facing the same issue. By any chance someone knows a workaround for remote webdriver? Works fine on localhost.

alexlazarciuc avatar Feb 14 '18 13:02 alexlazarciuc

And guys, this is not only C#, but java as well, and probably all the platforms you support.

DavidGangel avatar Feb 15 '18 09:02 DavidGangel

Does anyone has a useful workaround for now?

danielstepper avatar Mar 22 '18 13:03 danielstepper

Folks, this is a grid/remote issue, not unique to the .NET bindings. It works locally, as mentioned by several commenters, and surfaces when using RemoteWebDriver.

jimevans avatar Mar 22 '18 13:03 jimevans

Yes I agree with that. I am running in that issue with the Java bindings. And same problem in js: https://github.com/nightwatchjs/nightwatch/issues/1663

My test setup on Browserstack: geckodriver v0.19.1 selenium 3.10.0 Firefox v59.0

So does anyone has a workaround till a fix is implemented?

danielstepper avatar Mar 22 '18 14:03 danielstepper

This workaround works for me:

dstepper/selenium@2da0105#diff-578329ec7273c4a024979fd0ebcda293

danielstepper avatar Mar 26 '18 09:03 danielstepper

Same issue trying to change between tabs (page.driver.browser.switch_to.window(window.first)) using the ruby version. And yes.. the issue comes from the RemoteWebDriver

bott17 avatar Apr 02 '18 14:04 bott17

We've got the same issue. It's a Firefox related bug. The issue comes from the RemoteWebDriver.

iketari avatar Apr 05 '18 19:04 iketari

Same here, with SauceLabs, any other workaround?

shrohitpatel avatar Apr 05 '18 20:04 shrohitpatel

Need this fixed. It's breaking our SauceLabs tests using latest Firefox browser and latest Selenium driver (3.11.0). Any other tip on workarounds or timeframe to fix RemoteWebDriver?

lbfsmith169 avatar Apr 08 '18 21:04 lbfsmith169

Same here. Was trying a variety of version combinations of Ghecko and Selenium - nothing have worked for me on Browserstack.

dj-niobium avatar Apr 11 '18 12:04 dj-niobium

Any update on this? I am still getting this error with selenium 3.11 and gecko 0.20.1

org.openqa.selenium.WebDriverException: Missing 'handle' parameter Build info: version: '3.11.0', revision: '47706e36d0', time: '2018-04-12T17:34:58.597Z' System info: host: 'Flipboards-MacBook-Pro-3.local', ip: 'fe80:0:0:0:10d4:18d:9f8b:583c%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144' Driver info: driver.version: unknown Command duration or timeout: 19 milliseconds Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46' System info: host: 'Flipboards-MacBook-Pro-3.local', ip: '172.31.10.222', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144' Driver info: org.openqa.selenium.remote.RemoteWebDriver Capabilities [{moz:profile=/var/folders/r5/xsd59wl12g32smfydwvnwplw0000gn/T/rust_mozprofile.pPiG0p4qrIXN, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, moz:headless=false, platform=ANY, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, webdriver.remote.sessionid=6dfa7f98-f2f1-ee4d-98c0-6463d34607c1, acceptInsecureCerts=false, browserVersion=59.0.2, platformVersion=16.7.0, moz:processID=8389, browserName=firefox, platformName=darwin, moz:webdriverClick=true}] Session ID: 6dfa7f98-f2f1-ee4d-98c0-6463d34607c1

pkaur avatar Apr 12 '18 18:04 pkaur

I am also facing similar issue with Firefox browser 57 and Selenium 3.8.0 on SauceLab

mukeshmetacube avatar Apr 25 '18 12:04 mukeshmetacube

Can anybody provide a reproduction scenario with a standalone selenium server (not SauceLabs or BrowserStack)?

I can't reproduce the issue using the scenario from original post.

barancev avatar Apr 26 '18 20:04 barancev

@barancev I can not provide you such steps, but if that helps @dstepper seems to found already where the issue comes from: https://github.com/dstepper/selenium/commit/2da0105

DavidGangel avatar Apr 27 '18 11:04 DavidGangel

According to the specification [1], a client binding should pass 'handle' property for a W3C conformant implementations, where as a legacy implementations require a 'name' property [2].

I can see the only reason for this issue: an implementation (say, SauceLabs) requires a 'handle' property, pretending it being W3C conformant, but it does not report W3C conformance during negotiation phase, and a client binding sends legacy payload.

If my guess is correct, the issue should be fixed on SauceLabs side.

[1] https://w3c.github.io/webdriver/webdriver-spec.html#switch-to-window [2] https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#sessionsessionidwindow

barancev avatar Apr 27 '18 13:04 barancev

Let's look at .Net binding, for which the issue was reported, there are two branches: https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/Remote/RemoteTargetLocator.cs#L140 https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/Remote/RemoteTargetLocator.cs#L177

barancev avatar Apr 27 '18 13:04 barancev