Your ultimate guide

C# With NUnit _ Waits

 Implicit Wait:

Implicit wait for 5 seconds:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

// if the driver object is in the global level, then this one statement is applicable for entire class wherever we use drive object.

In the above statement we give implicit wait as 5 seconds, if the element is identifies in 3 seconds then it will take the element and continue the process, it will not wait until 5 seconds. 

 

Explicit Wait:

(To run Explicit Wait we need to download a package in NuGet called “Selenium Extras”)

 

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(8)));

wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions

.TextToBePresentInElementValue(driver

.FindElement(By.XPath(//input[@value=”singning”])) “sign-in”);

 

Here We create a object for WebDriverWait with the name of wait.

Then by using the object (wait). Until the value attribute change to “sign-in” on that particular web element it will wait. Here we give maximum wait 8 seconds so it will wait up to 8 seconds.

SeleniumExtras is namespace

WaitHelpers is a Class

ExpectedCondition is a method

TextToBePresentInElementValue is also method

No comments:

Post a Comment