Reputation: 83
IWebDriver driver = new RemoteWebDriver(uri, dc);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
** Search google and end up at a Google Search Results page
List<IWebElement> elements = new List<IWebElement>();
elements.AddRange(driver.FindElements(By.XPath("//*[@id=\"vn1s0p1c0\"]")));
When I run this, it works if the XPath exists on the page, but if that Xpath does not exist on the page, it will wait and then timeout at 60 seconds. I though the behaviour of FindElements was to return an empty list if the element is not found. No idea what I am doing wrong.
Upvotes: 1
Views: 797
Reputation: 16310
The issue is with specifying 60 second time to wait for searching that element. If you remove second line code which is setting waiting time, then it will returns empty list of IWebElement
if that element do not exist in the driver page. Otherwise, with specifying 60 second to search for that element will throw Timeout exception
after 60 second.
Following code would skip timeout issue :
IWebDriver driver = new RemoteWebDriver(uri, dc);
** Search google and end up at a Google Search Results page
List<IWebElement> elements = new List<IWebElement>();
elements.AddRange(driver.FindElements(By.XPath("//*[@id=\"vn1s0p1c0\"]")));
Upvotes: 2