如何对弹出窗口执行操作。它在某些操作之间随机显示?Selenium


case "single select type":
radioButtonStatus = webDriver.findElement(By.xpath("//p[contains(text(),'Single select type')]")).isDisplayed();
Random random=new Random();
int number=random.nextInt(5);
if(number==0)
{
number=number+1;
}
if (radioButtonStatus)
{
System.out.println("RadioButton"+number);
webDriver.findElement(By.xpath("path["+number+"]path/*[1]")).click();
Exam.clickOnSaveandNextButton();
}
break;

我写了一个带有开关盒的循环。如果循环是60次,则弹出窗口将出现在循环之间的不同点。

选项一-try/catch块:

try {
driver.switchTo().alert().accept();
}
catch (NoAlertPresentException e) {
}

选项二-使用org.openqa.selenium.support.ui.ExpectedConditions:

if (ExpectedConditions.alertIsPresent() != null) {
driver.switchTo().alert().accept();
}

最新更新