简体   繁体   中英

Handling custom pop-ups (not the default windows one) through selenium webdriver (3.x)

I want to automate a scenario.

When the browser lands on the website, there is a warning pop-up that requires a response to the prompt: Do you want to proceed?

There are two options Leave and Continue .

I am trying to switch the control with the following functions but its not working.

    Alert alert=driver.switchTo().alert();
    driver.switchTo().alert();
    alert.accept();

If its JavaScript alert, then driver.switchTo().alert().accept(); should work by accepting the default. Is this pop-up or modal window? Did you try to switch to window and click on the button? Also, which browser are you using? JavaScript alert might needs to handled differently based on the browser. If its modal or window, then getWindowHandle() should work fine.

String newWindow = driver.getWindowHandle();
driver.switchTo().window(newWindow);
//Switching to new window
driver.findElement(By.id("buttonId"));
//Switching back to default/main window
driver.switchTo().defaultContent();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM