Reputation: 199
My code with sleep works great but when I put to code implicit it doesn't.
Works
driver.Navigate().GoToUrl(http://bit.ly);
driver.FindElement(By.XPath("//*[@id='shorten_url']")).SendKeys("http://google.com");
Thread.Sleep(1500);
driver.FindElement(By.XPath("//*[@id='shorten_actions']")).Click();
outL.Text += driver.FindElement(By.XPath(//*[@id='shorten_actions']//input[@class='copy-input'])).GetAttribute("value") + "\r\n";
Doesn't work
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
driver.Navigate().GoToUrl("http://bit.ly");
driver.FindElement(By.XPath("//*[@id='shorten_url']")).SendKeys("http://google.com");
driver.FindElement(By.XPath("//*[@id='shorten_actions']")).Click();
outL.Text += driver.FindElement(By.XPath(//*[@id='shorten_actions']//input[@class='copy-input'])).GetAttribute("value") + "\r\n";
Can someone explain me why?
Upvotes: 1
Views: 89
Reputation: 2267
You should consider using a different approach as opposed to relying on the driver's implicit wait:
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(by));
You can wrap this up in a method
public static IWebElement FindElement(IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(by));
}
return driver.FindElement(by);
}
Hope this helps
Upvotes: 2