When you automate the test cases using Selenium webdriver, you will have to add synchronization points because page elements may take different time to load depending upon the network speed.
There are mainly 2 things to consider.
Other expected conditions are mentioned below.
What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com
There are mainly 2 things to consider.
- Page load is taking too long
- Some section of the page is loading asynchronously using ajax. In this case, even if the page is loaded, elements from the specific section of the page loading with ajax may take different times.
To handle these situations selenium webdriver provides 2 kinds of Waits.
- Implicit Waits
- Explicit Waits
1. Implicit Waits in Selenium Webdriver in C#.Net
We can specify the page load time out using below line of code. Remember that implicit waits are one time settings and work for until driver session exists.
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(50));
We can specify the element existence time out using below line of code.
driver.manage().timeouts().implicitlyWait(20,
TimeUnit.SECONDS);
2. Explicit Waits in Selenium Webdriver in C#.Net
We can use explicit waits to wait for specific condition on the element. Below code will wait for the element with id - dd to come into existence.
It will ignore the 2 exceptions - StaleElementReferenceException, InvalidElementStateException
WebDriverWait w = new
WebDriverWait(driver, TimeSpan.FromSeconds(20));
w.IgnoreExceptionTypes(typeof(StaleElementReferenceException),typeof(InvalidElementStateException));
w.Until(ExpectedConditions.ElementExists(By.Id("dd")));
- ElementIsVisible - wait until element becomes visible
- TitleContains - wait until title contains given substring
- TitleIs - wait until title matches given string
What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com
No comments:
Post a Comment