简体   繁体   中英

Selenium C#, WebDriverWait timeout

I wrote a console application (visual studio 2013, C#) to test my web site with selenium.

This is my code

    public static void Main(string[] args)
    {
        IWebDriver driver = new FirefoxDriver();
        driver.Navigate().GoToUrl("myUrl");

        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(40));
        wait.Until(ExpectedConditions.ElementExists(By.Id("wsConnected")));

        driver.Quit();
    }

wsConnected is a div I put in page with jquery after page load (less than 10 seconds).

I am using Selenium 2.46.0 with Firefox v39.0

Of course it doesn't work because I get the driver timeout error after 60 seconds, any help will be very appreciated.

Thanks, Alessandro

[UPDATE] wait.Until fails with this exception: An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.Support.dll. Additional information: The HTTP request to the remote WebDriver server for URL http://localhost:7056/hub/session/86847fde-462b-47be-85e1-31cd51791dc3/element timed out after 60 seconds.

[UPDATE 2] I downgraded Selenium to 2.43 and firefox to v32, no timeout, endless wait

Try to avoid using of ExpectedConditions.
Cause of error will be much more clear.
The next code was tested with the latest version of selenium (Selenium Support Classes 2.48.2 and WebDriver 2.48.2 from nuget packages). It works fine even if element become visible in 10 seconds.

IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("https://www.google.ru/");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(40));
wait.Until(d => d.FindElement(By.Id("logocont")));
driver.Quit();

If it does not help, please provide an inner exception of the timeout exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM