SeleniumHQ / selenium

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

[🐛 Bug]: WebDriverWait throws error instantly without waiting the any TimeSpan (C#) #11885

Closed aspeed98 closed 1 year ago

aspeed98 commented 1 year ago

What happened?

C# Using WebDriverWait throws error instantly, without waiting any amount of time given to it. Code I'm using is correct, in fact this code is 100% taken from the selenium.dev website. And of course OpenQA.Selenium.Support.UI is being imported to project. https://www.selenium.dev/documentation/webdriver/waits/

How can we reproduce the issue?

ChromeDriver driver = new ChromeDriver();
driver.Url = "https://www.google.com/ncr";
driver.FindElement(By.Name("q")).SendKeys("cheese" + Keys.Enter);

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement firstResult = wait.Until(e => e.FindElement(By.XPath("//div[id='obviously WRONG XPATH']")));

Console.WriteLine(firstResult.Text);
driver.Quit();

Relevant log output

OpenQA.Selenium.NoSuchElementException: "no such element: Unable to locate element: {"method":"xpath","selector":"//div[id='obviously WRONG XPATH']"}
(Session info: chrome=112.0.5615.50)

Operating System

Windows 11

Selenium version

4.8...

What are the browser(s) and version(s) where you see this issue?

Chrome 111, 112, ...

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 111.0.5563.64

Are you using Selenium Grid?

no grid

github-actions[bot] commented 1 year ago

@aspeed98, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

titusfortner commented 1 year ago

I can't duplicate this on Windows 11 with Chrome 111. We do need to change the example code, though.

try:

            driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html";
            driver.FindElement(By.Id("adder")).Click();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement added = wait.Until(d => d.FindElement(By.Id("box0")));
nvborisenko commented 1 year ago

@titusfortner I think you will be able to reproduce the issue within following code:

            driver.Url = "https://www.selenium.dev/selenium/web/dynamic.html";
            driver.FindElement(By.Id("adder")).Click();

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement added = wait.Until(d => d.FindElement(By.Id("UNKNOWN_ID")));

@aspeed98 you should add NoSuchElement exception as ignored while waiting element.

titusfortner commented 1 year ago

Hmm, that should be the default behavior, though. I'll try again.

nvborisenko commented 1 year ago

You are right, Titus.

Moreover, I executed original code and it works as expected: it waits 10 seconds and then throws exception.

diemol commented 1 year ago

Do we need to do something to fix this open issue? Or was it working as expected?

nvborisenko commented 1 year ago

Seems nothing to do from our side, it works as expected. I would ask @aspeed98 to provide cleaner steps for issue reproduction.

diemol commented 1 year ago

Closing as we did not get more information.

github-actions[bot] commented 11 months ago

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