adspace
Write a code to wait for a particular element to be visible on a page. Write a code to wait for an alert to appear.
Answer Posted / Ravi Shukla
To wait for an element to be visible on a page in Selenium WebDriver, you can use the `WebDriverWait` class with the `until()` method and `ExpectedConditions.visibilityOfElementLocated()`. Here's an example in Java:n```n // Create a WebDriverWait instancen WebDriverWait wait = new WebDriverWait(driver, 10);nn // Wait for the element to be visiblen WebElement myDynamicElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("myDynamicElementId")));n```nTo wait for an alert to appear, you can use the `alert` method and check if it's present as follows:n```n // Check if an alert is displayedn if (driver.switchTo().alert() != null) {n driver.switchTo().alert().accept();n }n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers