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


Please Help Members By Posting Answers For Below Questions

How can you fetch an attribute from an element? How to retrieve typed text from a textbox?

1197


Have you created any framework?

1039


Do you know how to locate a link using its text in selenium?

986


What’s selenese?

920


what will be the first salary and what will be the hike in the salary?

929