SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.48k stars 8.15k forks source link

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

Closed AndyUM357 closed 4 years ago

AndyUM357 commented 6 years ago

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 commented 6 years ago

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

DavidGangel commented 6 years ago

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.

jersmo commented 6 years ago

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.

alexlazarciuc commented 6 years ago

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

DavidGangel commented 6 years ago

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

dstep commented 6 years ago

Does anyone has a useful workaround for now?

jimevans commented 6 years ago

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.

dstep commented 6 years ago

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?

dstep commented 6 years ago

This workaround works for me:

dstepper/selenium@2da0105#diff-578329ec7273c4a024979fd0ebcda293

bott17 commented 6 years ago

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

iketari commented 6 years ago

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

shrohitpatel commented 6 years ago

Same here, with SauceLabs, any other workaround?

lbfsmith169 commented 6 years ago

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?

dj-niobium commented 6 years ago

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

pkaur commented 6 years ago

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

mukeshmetacube commented 6 years ago

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

barancev commented 6 years ago

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.

DavidGangel commented 6 years ago

@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

barancev commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Looking at the referenced patch I see it attempts to patch legacy codeс, that reinforces my guess.

shs96c commented 6 years ago

This seems to be a problem with the cloud providers --- Selenium itself is behaving properly. Presumably everyone experiencing issues here is raising the same issues with the cloud providers?

alexlazarciuc commented 6 years ago

Yes @shs96c Simon. Getting this on BrowserStack only. Works fine on local and grid.

tarar1 commented 6 years ago

Getting the same on the Sauclab with lasted firefox version using Selenium 3.8.0 with Ruby /Capybara .

DavidGangel commented 6 years ago

Hi all,

I notified SauceLabs about the issue, they have an open support ticket:

Hi David,

I completely agree - this is indeed something we are aware of and working on. We'll keep you updated.

Regards, Matt

I will let you know when I receive an update from them. @barancev Thank you for picking up this issue!

BeyondEvil commented 6 years ago

The workaround that works for me is to use W3C capas with SauceLabs (starting with selenium 3.11.0)

https://gist.github.com/BeyondEvil/aa95846716771dc635327022600b5cee

aglo65 commented 6 years ago

I'm facing similar issue with Firefox60 and Selenium 3.12.0 on Browserstack. Any suggestions on how to add the workaround for missing handle parameter i.e. set window-handle with parameter 'handle' instead of 'name' for firefox into a java file for JsonHttpCommandCodec.class in 'client-combined-3.12.0.jar' downloaded locally? Any idea on fixing this?

lmtierney commented 6 years ago

@aglo65 that would be an ETA from browserstack

DavidGangel commented 6 years ago

Hi all,

from SauceLabs I got the information that this should may fix the issue described in this ticket: https://wiki.saucelabs.com/display/DOCS/2018/03/27/Introducing+Selenium+WebDriver+W3C+Protocol+Beta

If someone has the possibility to try it out, can you please give us a feedback?

tarar1 commented 6 years ago

Hi,

I have the same issue and raised ticket with saucelab they said only way to solve this it to upgrade your environment according to the link you shared.

I upgraded the environment according to the instructions but my test is not even running on saucelab and it failed with

[exec] Instantiating driver with capabilities : {:platformName=>"Mac OS X 10.9", :browserName=>"firefox", :browserVersion=>"60.0", "sauce:options"=>{:seleniumVersion=>"3.8.0", :recordVideo=>true, :videoUploadOnPass=>true, :recordScreenshots=>true, :recordLogs=>true, :maxDuration=>10800, :screenResolution=>nil, :username=>"XXXXX", :accessKey=>"xxxxxxxxxx"}} [exec] Testing remote driver connection... [exec] Remote driver connection successful.Session id is 8c45fb0530ed4f737a3a9f0cf3eb9f81360d [exec] [exec] Examples how to use framework part 1 [exec] SauceOnDemandSessionID=8c45fb0530ed4f737a3a9f0cf3eb9f81360d job-name=Examples how to use framework part 1 [exec] select app (FAILED - 1) [exec] F [exec] [exec] Failures: [exec] [exec] 1) Examples how to use framework part 1 select app [exec] Failure/Error: raise Error::WebDriverError, msg [exec] [exec] Selenium::WebDriver::Error::WebDriverError: [exec] unexpected response, code=400, content-type="text/plain" [exec] {"value": {"stacktrace": "Syntax error at :1:1", "message": "Failed to decode request as JSON: \"\"", "error": "invalid argument"}} [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/common.rb:88:in create_response' [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/default.rb:104:inrequest' [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/http/common.rb:59:in call' [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/bridge.rb:164:inexecute' [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/w3c/bridge.rb:535:in execute' [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/remote/w3c/bridge.rb:358:inclick_element' [exec] # ./ruby/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/common/element.rb:72:in `click'

Saucelab responded and looking into this.

I use ruby binding with capybara.

Thanks

Faraz


From: DavidGangel notifications@github.com Sent: 22 May 2018 09:59 To: SeleniumHQ/selenium Cc: tarar1; Comment Subject: Re: [SeleniumHQ/selenium] WebDriver v3.7.0 C# Firefox "missing handle parameter" for popup windows (#5064)

Hi all,

from SauceLabs I got the information that this should may fix the issue described in this ticket: https://wiki.saucelabs.com/display/DOCS/2018/03/27/Introducing+Selenium+WebDriver+W3C+Protocol+Beta

Introducing Selenium WebDriver W3C Protocol Beta - The ...https://wiki.saucelabs.com/display/DOCS/2018/03/27/Introducing+Selenium+WebDriver+W3C+Protocol+Beta wiki.saucelabs.com Return to the Product Announcements and Release Notes Blog. Sauce Labs is happy to announce beta support for the W3C capabilities and protocol on Selenium 3.8.0 and above. Some features are now being added to Selenium, which are only available when executing the W3C protoco

If someone has the possibility to try it out, can you please give us a feedback?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/SeleniumHQ/selenium/issues/5064#issuecomment-390915683, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AI5uVYGHWjJ8Z2nMJ5uRDZNk1FjAdoLBks5t09NdgaJpZM4Qgio4.

DavidGangel commented 6 years ago

Hi Faraz,

thank you for your update! Please keep posting results anything you may receive from SauceLabs.

For everybody else who is using BrowserStack: I found a setting on this page called: browserstack.use_w3c https://www.browserstack.com/automate/capabilities

I guess this is a kind of same story then over SauceLabs, so you might start trying it out.

dj-niobium commented 6 years ago

Adding that cap didn't help for me with Browserstack. Still the same "WebDriverException: Message: Missing 'handle' parameter" issue.

On Tue, 22 May 2018 at 11:24, DavidGangel notifications@github.com wrote:

Hi Faraz,

thank you for your update! Please keep posting results anything you may receive from SauceLabs.

For everybody else who is using BrowserStack: I found a setting on this page called: browserstack.use_w3c https://www.browserstack.com/automate/capabilities

I guess this is a kind of same story then over SauceLabs, so you might start trying it out.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/SeleniumHQ/selenium/issues/5064#issuecomment-390941096, or mute the thread https://github.com/notifications/unsubscribe-auth/AH4HsdNgkgQOk587enHvmDaJ1_1Z93F0ks5t0-dzgaJpZM4Qgio4 .

DavidGangel commented 6 years ago

@dj-niobium did you also changed the capability names as asked by BrowserStack: if this is enabled, we assume that your Selenium capabilities are compliant with the W3C-spec. Read more here - as described here: https://www.w3.org/TR/webdriver/#capabilities

If yes and you still have issue, it would be best to get in touch with the support of browserstack in this topic.

aglo65 commented 6 years ago

I've opened a ticket with Browserstack and was advised to try the following: Excerpt from Browsersrack Support The issue is specific to the Firefox browser. Could you please add the capability 'browserstack.use_w3c' in your tests try again?
**Please note that when you use this capability, you need to replace the capability 'browser_name' with 'browserName' and 'browser_version' with 'browserVersion' as below.

caps.setCapability("os", "Windows");
caps.setCapability("os_version", "8");
caps.setCapability("browserName", "Firefox");
caps.setCapability("browserVersion", "59.0");
caps.setCapability("browserstack.use_w3c", true);

I've tried the proposed solution and the "handle" related error is gone, but the test failed on the click action as this actions in my script(see below) is trying to perform are out of the browser window viewport whose dimensions are 715x402. Browserstack support is looking into this now. Will keep you posted.

public static void clickAtBottomLeftIcon(WebDriver IWebDriver1, WebElement WebElem) {
Log.info("Clicking on Mybug");
new Actions(IWebDriver1).moveToElement(WebElem, 0, 0)
moveByOffset(getBottomLeftX(WebElem), getBottomleftY(WebElem)).click().build().perform();
Log.info("Clicked on Mybug");

lmtierney commented 6 years ago

@aglo65 that is per the w3c spec. You need to scroll it into view if you want to use Actions. Refer to https://w3c.github.io/webdriver/#pointer-actions specifically When required to dispatch a pointerMove action...

aglo65 commented 6 years ago

Thanks @lmtierney ! Will give it a shot ...

DavidGangel commented 6 years ago

@tarar1 @aglo65 at the end were you able to overcome your issues?

aglo65 commented 6 years ago

@DavidGangel Yes. The original issue was fixed by adding caps.setCapability("browserstack.use_w3c", true); as per you suggestion. To address the second issue, I've adjusted te offset values of x, y coordinates in the Coordinate.Utils java so its clicking the right area in the canvas. Thanks for following up!

p0deje commented 6 years ago

Should this issue be kept open or closed then?

barancev commented 6 years ago

It should be closed, but may be we have to add documentation for this case?

Muraliyasam commented 5 years ago

org.openqa.selenium.InvalidArgumentException: Missing 'handle' parameter. when I am running script locally it is working fine and when I am running script on jenkins we are getting the issue "org.openqa.selenium.InvalidArgumentException: Missing 'handle' parameter"

wizbanicus commented 5 years ago

Hey - anyone still struggling with this after following the advice of adding the caps.setCapability("browserstack.use_w3c", true); I found I needed to use a specific combination of selenium, gecko and Firefox: caps.setCapability("browser", "Firefox"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "10"); caps.setCapability("resolution", "1024x768")); caps.setCapability("browserstack.local", "false"); caps.setCapability("browserstack.selenium_version", "3.11.0")); caps.setCapability("browserstack.geckodriver", "0.22.0"); caps.setCapability("browserstack.use_w3c","true"); caps.setCapability("browserName", "Firefox"); caps.setCapability("browserVersion", "64.0"); caps.setCapability("browser_name", "Firefox"); caps.setCapability("browser_version", "64.0"); some uneeded stuff here but that th full list I have been using .

alexlazarciuc commented 5 years ago

Hey @wizbanicus,

What's the error you get when you use that cap on BS? Recently I've discovered that w3c one it is not working with Chrome on their end and they're about to fix it. I will try with Firefox and comeback.

Alex.

Hassan-Radi commented 5 years ago

Hey @wizbanicus

You are still getting the above error because your session is still not working in the W3C mode (even after providing the browserstack.use_w3c capability). All you need to get it working is remove the following from your capabilities:

caps.setCapability("browser_name", "Firefox"); caps.setCapability("browser_version", "64.0");

Let me know how it goes?

Hassan

diemol commented 4 years ago

Closing this as the error was happening only in cloud providers

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.