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

久未见 提交于 2019-12-12 02:17:55

问题


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();

回答1:


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();


来源:https://stackoverflow.com/questions/42796726/handling-custom-pop-ups-not-the-default-windows-one-through-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!