handle customized popup in selenium

‮w//:sptth‬ww.lautturi.com
handle customized popup in selenium

To handle a customized popup in Selenium, you can use the WebDriverWait class to wait for the popup to appear and then use the WebElement methods to interact with the elements in the popup.

Here's an example of how you can handle a customized popup in Selenium:

// wait for the popup to appear
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#popup")));

// find the elements in the popup
WebElement popup = driver.findElement(By.cssSelector("#popup"));
WebElement closeButton = popup.findElement(By.cssSelector("button.close"));
WebElement submitButton = popup.findElement(By.cssSelector("button.submit"));

// interact with the elements
closeButton.click(); // close the popup
submitButton.click(); // submit the form in the popup

In this example, the WebDriverWait class is used to wait for the popup to appear, and the visibilityOfElementLocated() method is used to check if the popup is present on the page. Once the popup is found, the findElement() method is used to locate the close button and the submit button in the popup. The click() method is then used to interact with these elements.

You can customize this example by using different By strategies to locate the elements in the popup, such as using an element's ID, class name, or tag name. You can also use other methods from the WebElement interface to interact with the elements in the popup, such as sendKeys() to enter text or isDisplayed() to check if an element is visible.

Created Time:2017-11-01 12:05:04  Author:lautturi