What is "Synchronization" in selenium || How we can achieved synchronization in our Testing || What is "Waits" - Types || Example of Synchronization
What is Synchronization?
- Synchronization is achieving the coordination between the WebElements.
- Synchronization helps us avoid exceptions in selenium such an no such element exception by adding the waits.
Types of Waits
- UnConditional Waits
- Conditional Waits
Types of UnConditional Waits
- driver.sleep
- driver.wait
Types of Conditional Waits
- Implicate Wait
- Explicate Wait
- Fluent Wait.
Implicate Wait
- This type of wait is only applicable to FindElement or FindElements methods in Selenium.
- Implicate Wait is use after we initiate the driver.
- For instance
Public class ImpliciteWait{
static void wait(WebDriver driver) {
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}
}
Note: Even though we set a wait for 10 seconds, selenium will not wait if we find the
element before 10 seconds.
If selenium is unable to find the element in specified time, it will give us timeout Exception
Explicate Wait
static WebDriver driver = null;
static void wait(WebDriver driver) {
driver= new ChromeDriver();
String UserName = null;
WebElement MyUserName = driver.findElement(By.name(UserName));
WebDriverWait Mywaits = new WebDriverWait(driver, Duration.ofSeconds(20));
Mywaits.until(ExpectedConditions.elementToBeClickable(MyUserName));
}
}
Fluent Wait.
static void wait(WebDriver driver) {
driver = new ChromeDriver();
WebDriverWait MyFluentWait = new WebDriverWait(driver, Duration.ofSeconds(30));
MyFluentWait.pollingEvery(Duration.ofSeconds(10));
}
}
Comments
Post a Comment