Selenium: WebDriverWait is immediately raising a BROWSER_TIMEOUT exception rather than waiting for the given amount of time

Created on 14 Aug 2017  路  20Comments  路  Source: SeleniumHQ/selenium

Meta -

OS:
Windows 10
Selenium Version:
3.5.0
Browser:
Firefox 55.0.1

Browser Version:

Expected Behavior -

Running Selenium 3.5.0 in a grid, I would expect a WebDriverWait to run for a given amount of time, then a Message: OpenQA.Selenium.WebDriverTimeoutException exception to be raised.

Actual Behavior -

The wait fails immediately with a Message: System.InvalidOperationException : Session [2647d75b-987e-4797-99d3-e49eb1c4227a] was terminated due to BROWSER_TIMEOUT exception.

Downgrading Selenium to 3.3.0 resolves this and the wait works correctly.

Steps to reproduce -

Hub config;

{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": true
}

Test

using System;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

namespace UnitTestProject1
{
    [TestFixture]
    public class UnitTest1
    {

        public UnitTest1()
        {
        }

        [Test]
        public void TestMethod1()
        {
            IWebDriver driver;

            FirefoxOptions options = new FirefoxOptions();
            options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";

            driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
            driver.Navigate().GoToUrl("https://google.com");

            WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            IWebElement element = waits.Until(ExpectedConditions.ElementIsVisible(By.Id("THISELEMENTIDDOESNOTEXIST")));
        }
    }
}

Run the above code sample with Selenium 3.5.0, geckodriver 0.18 and Firefox.

C-grid I-defect

Most helpful comment

Status report: reproduced, found the root cause, looking for a solution.

All 20 comments

Logging from a 3.5.0 test;

15:33:35.495 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@6c601ab
15:33:35.513 INFO - Handler thread for session 7cc73b5e-25f8-4797-beab-9d84020721d7 (firefox): Executing POST on /session/7cc73b5e-25f8-4797-beab-9d84020721d7/element (handler: ServicedSession)
15:33:35.529 INFO - To upstream: {"using":"css selector","value":"#THISELEMENTIDDOESNOTEXIST"}
15:33:35.565 INFO - To downstream: {"value":{"error":"no such element","message":"Unable to locate element: #THISELEMENTIDDOESNOTEXIST","stacktrace":"stack backtrace:\n   0:           0x4bb74f - <no info>\n   1:           0x4bbea9 - <no info>\n   2:           0x43ce8d - <no info>\n   3:           0x44ce14 - <no info>\n   4:           0x44944a - <no info>\n   5:           0x4203e1 - <no info>\n   6:           0x407dc7 - <no info>\n   7:           0x6d95b9 - <no info>\n   8:           0x4173a7 - <no info>\n   9:           0x6d38b3 - <no info>\n  10:     0x7fff22e12774 - BaseThreadInitThunk"}}
15:33:36.244 INFO - Found handler: org.openqa.selenium.remote.server.com

Internet Explorer 11 seems to have the same issue;

using System;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.IE;

namespace UnitTestProject1
{
    [TestFixture]
    public class UnitTest1
    {

        public UnitTest1()
        {
        }

        [Test]
        public void TestMethod1()
        {
            IWebDriver driver;

            //FirefoxOptions options = new FirefoxOptions();
            //options.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";

            InternetExplorerOptions options = new InternetExplorerOptions();

            driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
            driver.Navigate().GoToUrl("https://google.com");

            WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            IWebElement element = waits.Until(ExpectedConditions.ElementIsVisible(By.Id("THISELEMENTIDDOESNOTEXIST")));
        }
    }
}

Message: System.InvalidOperationException : Session [9ceca9aa-e7c1-4dd3-b04a-0d01eba542cd] was terminated due to BROWSER_TIMEOUT

I cannot test Chrome, due to #4443

VS2107 output from failed Internet Explorer 11 test;

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs : line 22
Test Outcome:   Failed
Test Duration:  0:00:04.021

Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs:line 34
Result Message: System.InvalidOperationException : Session [9ceca9aa-e7c1-4dd3-b04a-0d01eba542cd] was terminated due to BROWSER_TIMEOUT

Using .NET 3.5.1 Selenium release from #4443 I have now tested this with Chrome and found that the WebDriverWait command waits for the given time period.

Here's the VS2017 output from a Chrome test;

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs : line 22
Test Outcome:   Failed
Test Duration:  0:00:33.415

Result StackTrace:  
at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs:line 35
--NoSuchElementException
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
Result Message: 
OpenQA.Selenium.WebDriverTimeoutException : Timed out after 30 seconds
  ----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"id","selector":"THISELEMENTIDDOESNOTEXIST"}
  (Session info: chrome=60.0.3112.90)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)

Then I believe this is fixed in 3.5.1 and this issue can be closed.

Sorry, my bad, this bug shouldn't be closed. Here's clarification;

Chrome, with Selenium 3.5.1

[Test]
public void TestMethod1()
{
    IWebDriver driver;

    //FirefoxOptions options = new FirefoxOptions();
    //options.BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe";

    //InternetExplorerOptions options = new InternetExplorerOptions();

    ChromeOptions options = new ChromeOptions();

    driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
    driver.Navigate().GoToUrl("https://google.com");

    WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
    IWebElement element = waits.Until(ExpectedConditions.ElementIsVisible(By.Id("THISELEMENTIDDOESNOTEXIST")));
}

Outcome: test fails in the expected manner:

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs : line 22
Test Outcome:   Failed
Test Duration:  0:00:33.346

Result StackTrace:  
at OpenQA.Selenium.Support.UI.DefaultWait`1.ThrowTimeoutException(String exceptionMessage, Exception lastException)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs:line 36
--NoSuchElementException
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
Result Message: 
OpenQA.Selenium.WebDriverTimeoutException : Timed out after 30 seconds
  ----> OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"id","selector":"THISELEMENTIDDOESNOTEXIST"}
  (Session info: chrome=60.0.3112.90)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)

Internet Explorer with Selenium 3.5.1

[Test]
public void TestMethod1()
{
    IWebDriver driver;

    //FirefoxOptions options = new FirefoxOptions();
    //options.BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe";

    InternetExplorerOptions options = new InternetExplorerOptions();

    //ChromeOptions options = new ChromeOptions();

    driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
    driver.Navigate().GoToUrl("https://google.com");

    WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
    IWebElement element = waits.Until(ExpectedConditions.ElementIsVisible(By.Id("THISELEMENTIDDOESNOTEXIST")));
}

Test fails unexpectedly:

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs : line 22
Test Outcome:   Failed
Test Duration:  0:00:04.111

Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs:line 36
Result Message: System.InvalidOperationException : Session [4372bc3e-d505-4111-b72f-d027ce90d94b] was terminated due to BROWSER_TIMEOUT

Firefox with Selenium 3.5.1

[Test]
public void TestMethod1()
{
    IWebDriver driver;

    FirefoxOptions options = new FirefoxOptions();
    options.BrowserExecutableLocation = @"c:\program files\mozilla firefox\firefox.exe";

    //InternetExplorerOptions options = new InternetExplorerOptions();

    //ChromeOptions options = new ChromeOptions();

    driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
    driver.Navigate().GoToUrl("https://google.com");

    WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
    IWebElement element = waits.Until(ExpectedConditions.ElementIsVisible(By.Id("THISELEMENTIDDOESNOTEXIST")));
}

Test fails unexpectedly:

Test Name:  TestMethod1
Test FullName:  UnitTestProject1.UnitTest1.TestMethod1
Test Source:    C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs : line 22
Test Outcome:   Failed
Test Duration:  0:00:05.961

Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass2.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at OpenQA.Selenium.Support.UI.ExpectedConditions.<>c__DisplayClass13.<ElementIsVisible>b__12(IWebDriver driver)
   at OpenQA.Selenium.Support.UI.DefaultWait`1.Until[TResult](Func`2 condition)
   at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\MattHorrocks\Documents\Visual Studio 2017\Projects\SelTest350\UnitTestProject1\UnitTest1.cs:line 36
Result Message: System.InvalidOperationException : Session [4463be50-988c-47fa-9885-cc17938bfb96] was terminated due to BROWSER_TIMEOUT

Selenium Bindings: 3.5.1 .NET
GeckoDriver: 0.18.0
Firefox Version: 55.0.2
Selenium Jar: 3.5.1

Confirming that I'm seeing the same thing. As part of the login to the web app I am testing, I have to wait and see if a message modal appears so I can dismiss it. Most of the time, it does not so my tests will ignore the element not found error and move on.

When running against Firefox locally and not using the standalone server, Firefox is able to log in and complete my tests.

When running against the standalone server, not in a grid, Firefox is able to log in and complete my tests.

When running in a grid configuration with a separate hub and node, I get a browser timeout when Firefox cannot find the alert modal when it should keep processing the test.

This issue happens on Selenium Python binding also.

Selenium Bindings: 3.5.0 Selenium Python
GeckoDriver: 0.18.0
Firefox Version: 55.0.2
Selenium Jar: 3.5.1

Still not resolved in C#
Selenium Bindings: 3.5.1 C#
GeckoDriver: 0.18.0
Firefox Version: 55.0.2
Selenium Jar: 3.5.2

Additionaly, geckodriver.exe and firefox.exe will never be killed by grid.

This issue is also in Java 3.5.2 using grid with Internet Explorer 11. Chrome is ok.

Selenium Bindings: 3.5.2 Java
Selenium Jar 3.5.2
IEDriverServer 3.5 32bit
ChromeDriver 2.31

org.openqa.selenium.Web
DriverException: Session [5a1d463b-9fa4-46bb-bca7-0ec359b237fb] was terminated due
to BROWSER_TIMEOUT
Build info: version: '3.5.2', revision: '10229a9', time: '2017-08-21T17:29:55.15Z'

Status report: reproduced, found the root cause, looking for a solution.

Fixed in version 3.5.3 released today.

@barancev: will it be released like the other releases in this repository? Currently, 3.4.0 is presented as the latest release

We don't usually upload files to GitHub's Releases page (except for source tarballs).
Go to http://www.seleniumhq.org/download/ to get selenium server.
Client libraries are available in maven central repository.

So what is https://github.com/SeleniumHQ/selenium/releases about if not released versions?

Selenium repository is a monorepo so different language bindings are kept together. This is why Java bindings are available via Maven and Ruby bindings are available via Rubygems. Having a single releases page for all bindings would be a mess, which is why we only keep tarballs of sources there.

@p0deje that's what I got already. But why does this overview list v3.4.0 as the latest release with a nice changelog while there seems to be more recent versions?

That's the latest release done for all the language bindings, while specific languages do their own point releases.

@NicoHaase the releases page is basically just dedicated for a commit changelog between releases, and to show users that it's out. i've updated the releases page to show 3.5.3 as latest

Was this page helpful?
0 / 5 - 0 ratings