Wednesday, 20 June 2018

Selenium with C# (Waiting)

Selenium with C# (Waiting)
 0.cs
webdriver.FindElement(By.Id("search_button")).Click();
Thread.Sleep(5000);
IWebElement searchResult = webdriver.FindElement(By.Id("search_result"));
 1.cs
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"));
 2.cs
WebDriverWait webdriverWait = new WebDriverWait(webdriver, TimeSpan.FromSeconds(5));
IWebElement searchResult = webdriverWait.Until(x=>x.FindElement(By.Id("search_result")));
 3.cs
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")));

No comments:

Post a Comment

What to do to make sure HTML Table is loaded completely if implicit and explicit wait are not working.

These days I was working on a project, to implement the delete function of a listing. Such as below: Actually,  every time deleted the it...