问题
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