implicit wait: it sets a numeric value for the wait and it applies to the whole script. That means the script delays the given amount of waiting time.
Explicit wait: It applies only to a specific element until a specific condition is met it will wait. The time given in the wait is the maximum amount of time it waits until the condition is met.
Fluent wait: It gives more flexibility for waiting. It provides polling frequency and conditions such as ignoring errors.
2. How to add implicit wait in selenium?
- it waits a specified amount of time before throwing a NoSuchElementException.
driver.manage().timeouts().implicitlyWait(3, Timeunit.SECONDS);
3. How to add explicit wait?
//WebDriverWait(driver, time)
//here default unit is seconds
//time is long
WebDriverWait wait = new WebDriverWait(driver,10)
wait.until(ExpectedConditions.elementIsVisible(By.id('row'));
4. Can you provide an example of fluent wait?
- It provides a frequency of checking: polling interval
- Provide specific conditions like ignoring exceptions during the polling interval
Wait wait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30).
pollingEvery(Duration.ofSeconds(5)
.ignoring(NoSuchelementException.class);
WebElement element = wait.until(ExpectedConditions.
presenceOfElementLocated(By.id("exampleElement")));
element.click();
5. Explain the concept of ExpectedConditions.
ExpectedConditions is a class that provides a set of predefined conditions checked during waiting time such as the element is clickable, visible etc…
6. What are the sample of expected conditions?
- elementToBeClickable(WebElement element or By locator)
- stalenessOf(WebElement element)
- visibilityOf(WebElement element)
- visibilityOfElementLocated(By locator)
- invisibilityOfElementLocated(By locator)
- attributeContains(WebElement element, String attribute, String value
- alertIsPresent()
- titleContains(String title)
- titleIs(String title)
- textToBePresentInElementLocated(By, String)
- elementSelectionStateToBe()
- elementToBeSelected()
- frameToBeAvaliableAndSwitchToIt()
- invisibilityOfElementWithText()
- presenceOfAllElementsLocatedBy()
- presenceOfElementLocated()
- textToBePresentInElement()
- textToBePresentInElementValue()
- visibilityOfAllElements()
- visibilityOfAllElementsLocatedBy()
7. Difference between thread.sleep() and explicit wait()
thread. sleep() is a static wait which pauses the entire execution within the specified period.
explicit wait: it will continue the script execution as soon as the condition is met.
8. How to handle timeout in selenium?
- Use implicit wait
- WebDriverWait like explicit wait
- Use pageLoadTimeout
- Use setScriptTimeOut
9. How to deal with dynamic wait in selenium?
- Use explicit wait with expected conditions are met before proceeding with the next step.
- So it will make sure we are waiting only the necessary time and it avoids unnecessary long waits.
10. How to handle synchronization issues?
- Synchronous — task is executed in an order, one after another
- Asynchronous — tasks are executed simultaneously
- To handle synchronization we can use waits
- Thread.sleep(2000);
- Implicit wait
- Explicit wait
- Fluent wait
11. How do you handle network latency?
- Implicit wait
- Explicit wait
- Fluent wait
- setPageLoadTimeout (Sets the amount of time to wait for a page load to complete before throwing an error)
12. What is pageLoadTimeout()?
- Maximum time allowed to load the page completely
- Sets the amount of time to wait for a page load to complete before throwing an error
- Seconds is the default unit of measurement
driver.manage().timeouts().pageLoadTimeout(Duration(10))
13. What are the diffrent types of waiting in Selenium
Implicit wait
- This provide default waiting time EX: 10 seconds
Explicit wait
- This is used to halt the execution until specific conditions are met or the maximum time is elapsed
14.What does setScriptTimeout mean?
- When we load a website, Javascript may take some time to complete the whole page loading
- So we want to make sure that selenium scripts wait a considerable amount of time until asynchronous javascript finishes execution
- If script execution exceeds the specified time it will throw a timeout exception
- we can set setScriptTimeout(10, Time.SECONDS)
- This means asynchronous javascript needs to execute within this time frame (10 seconds)
- JavaScriptExecutor is the interface.
- It uses the executeAsyncScript() method to execute asynchronous javascript scripts
No comments:
Post a Comment