Unable to detect Alert using ChromeDriver?

孤街醉人 提交于 2021-02-19 09:07:20

问题


I am currently doing some automation testing using Selenium WebDriver. The issue I am facing is that my script is unable to detect alerts.

Scenario:

I open the application, pass my credentials and press Confirm. On Confirm, the application opens with an Alert. Screenshot of the Alert Shown below:

I am using Java, Selenium WebDriver, ChromeDriver, and testng.

i am using the codes shows below :

uk.setLogin("", "");

uk.getLogin();

WebDriverWait  wait = new WebDriverWait(Driver, 10);

wait.until(ExpectedConditions.alertIsPresent());

Alert alert = Driver.switchTo().alert();

alert.accept();

回答1:


What you are asking is not a Javascript Alert, it's called ConfirmBox.

ConfirmBox or Prompt Popups need to be handled differently than Alert Box.

Please try as below

Alert alert=driver.switchTo().alert();
System.out.println(alert.getText());
alert.dismiss();

It's explained here



来源:https://stackoverflow.com/questions/41741591/unable-to-detect-alert-using-chromedriver

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