Skip to content

Instantly share code, notes, and snippets.

@up1
Last active September 16, 2021 17:27
Show Gist options
  • Select an option

  • Save up1/d925783ea8e5f706f3bb58c3ce1ef7eb to your computer and use it in GitHub Desktop.

Select an option

Save up1/d925783ea8e5f706f3bb58c3ce1ef7eb to your computer and use it in GitHub Desktop.
Selenium with C# (Waiting)
webdriver.FindElement(By.Id("search_button")).Click();
Thread.Sleep(5000);
IWebElement searchResult = webdriver.FindElement(By.Id("search_result"));
IWebDriver webdriver = new ChromeDriver();
webdriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
webdriver.FindElement(By.Id("search_button")).Click();
IWebElement searchResult = webdriver.FindElement(By.Id("search_result"));
WebDriverWait webdriverWait = new WebDriverWait(webdriver, TimeSpan.FromSeconds(5));
IWebElement searchResult = webdriverWait.Until(x=>x.FindElement(By.Id("search_result")));
DefaultWait<IWebDriver> fluentWait = new DefaultWait<IWebDriver>(webdriver);
fluentWait.Timeout = TimeSpan.FromSeconds(5);
fluentWait.PollingInterval = TimeSpan.FromMilliseconds(250);
fluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
IWebElement searchResult = fluentWait.Until(x=>x.FindElement(By.Id("search_result")));
@aiden-sobey
Copy link

Great code here, thanks for sharing!

@wocar
Copy link

wocar commented Dec 22, 2019

Thank you :)

@qualitydude
Copy link

qualitydude commented Jul 10, 2020

Thank you :) that was useful

@Neshaminy1
Copy link

Thank you. It's really helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment