Selenium Java句柄对象(警报对话框)异常而不延迟。(不可预测的Java弹出窗口)
目标:警报弹出窗口。无论它是否显示,我希望它继续。如果显示,则必须选中复选框,然后单击“继续”。如果没有,请忽略 阻止程序:如果显示警报,它将处理该操作并关闭对话框。但当它不是,硒挂在那里没有处理条件时,它没有显示 背景:我以前使用过UFT,可能是我的逻辑错误。 弹出窗口是应用程序警报(不是系统),因此假设“切换到(),接受()/解除()”不起作用。我将在登录后立即在下面的登录方法中添加句柄警报 Selenium框架背景。我们使用Selenium maven框架,serenity BDD.object设置在页面的开头,serenity.properties处理超时默认值等等 弹出对象(如果出现): *登录方法*Selenium Java句柄对象(警报对话框)异常而不延迟。(不可预测的Java弹出窗口),java,maven,selenium,serenity-bdd,findby,Java,Maven,Selenium,Serenity Bdd,Findby,目标:警报弹出窗口。无论它是否显示,我希望它继续。如果显示,则必须选中复选框,然后单击“继续”。如果没有,请忽略 阻止程序:如果显示警报,它将处理该操作并关闭对话框。但当它不是,硒挂在那里没有处理条件时,它没有显示 背景:我以前使用过UFT,可能是我的逻辑错误。 弹出窗口是应用程序警报(不是系统),因此假设“切换到(),接受()/解除()”不起作用。我将在登录后立即在下面的登录方法中添加句柄警报 Selenium框架背景。我们使用Selenium maven框架,serenity BDD.obj
public void loginIntoExtApplication(String baseURL, String loginURL, String uId, String pwd, String extAppEnv)throws Exception {
gotoExtLoginPage(baseURL, loginURL);
enterLoginCredential(uId, pwd);
openAt("https://" + extAppEnv + ".programportaltest.hrsa.gov/sdms-
extranet/index.xhtml");
我的方法:
//一,
//2.登录操作后挂在此处
if(!getDriver().findElements(By.xpath("//*[@id='submit']")).isEmpty()){
PcoNoticeChbx.click();
PcoNoticeContinueBtn.click();
}
else {
System.out.println("Dialog didn't display, no need any action");
}
//3.添加到watch不起作用,它显示挂起,下面的代码也失败了。我在Junit的调试模式下运行了我的Maven。它过去工作得很好。但是watch元素总是显示(挂起)
//4.甚至尝试了试抓法
try{
PcoNoticeChbx.click();
PcoNoticeContinueBtn.click();
}catch (Exception e){
// Printing logs for my report
Log.error("Report Category button element is not found.");
// After doing my work, now i want to stop my test case
throw(e);
}
return;
}
//5.试用列表webelemets:
List temp=webdriver.findElements(org.openqa.selenium.By.id(“noticebox”)
//6.及以下
if (!WebDriver.findElements(By.xpath("//*[@id='submit']")).isEmpty()==true);
{
//handle the dialog
}
else{
//continue
}
//7.尝试使用布尔值,但它也挂起在这里的第一步
boolean Nbox = PcoNoticeChbx.isDisplayed(); {
if (Nbox==false)
{
System.out.println("Dialog didn't display, no need any action");
}
else if (Nbox==true) {
PcoNoticeChbx.click() ;
PcoNoticeContinueBtn.click();
}
如果这是我处理过的弹出窗口,它们的工作原理如下:
没有更多的弹出窗口。为我的案例找到了解决方案 这可能很容易。但我需要一些时间来研究。希望它能帮助你 在使用了许多方法之后,对于这个javascripts确认警报。我使用了下面的方法。所有关于.CurrentlyVisible()方法的帮助。因为这一个,我想只有这一个会给出结果,即使元素不存在或为null
if (element(NoticeContinueBtn).**isCurrentlyVisible**()==true) {
PcoNoticeChbx.click();
PcoNoticeContinueBtn.click();
//else just continue
}
当使用try-catch代码时,它停止为:element not clickable.public void checkAlert(){try{WebDriverWait wait=new WebDriverWait(getDriver(),2);System.out.println(“尝试步骤”);wait.until(ExpectedConditions.alertIsPresent());org.openqa.selenium.Alert=getDriver().switchTo().Alert();alert.accept();//}catch(异常e){//Exception handling System.out.println(“catch Exception steps”);}}}}}嗨,JeffC。这实际上是我的一个新想法。它适用于我的一些测试,类似于你的。另外,这不是基于cookie的警告,而是DB。
if (temp.Count > 0 && temp[0].Displayed) {
// script to execute if element is found
} else {
// continue the test
}
if (!WebDriver.findElements(By.xpath("//*[@id='submit']")).isEmpty()==true);
{
//handle the dialog
}
else{
//continue
}
boolean Nbox = PcoNoticeChbx.isDisplayed(); {
if (Nbox==false)
{
System.out.println("Dialog didn't display, no need any action");
}
else if (Nbox==true) {
PcoNoticeChbx.click() ;
PcoNoticeContinueBtn.click();
}
if (element(NoticeContinueBtn).**isCurrentlyVisible**()==true) {
PcoNoticeChbx.click();
PcoNoticeContinueBtn.click();
//else just continue
}