目标:弹出警报。无论是否显示,我都希望它继续。如果显示,必须选中复选框,然后点击继续。如果没有,请忽略。
拦截器:如果显示警报,它将处理该操作并关闭对话框。但如果不是,硒挂在那里没有处理条件,当它没有显示。
背景:我以前使用过 UFT,也许我的逻辑可能是错误的。弹出的是应用程序警报(不是系统),因此假设“切换到(),接受()/解雇()将不起作用。我将在登录后立即添加句柄警报,并在下面的登录方法中。
硒框架背景。:我们使用 selenium maven 框架,serenity BDD。对象设置在页面的开头。和 serenity.properties 处理超时默认值等等。
弹出对象(如果出现):
@FindBy(xpath = "//input[@id='notification-ack']")
private WebElement PcoNoticeChbx; //this is a check box, needs to be checked
@FindBy(xpath = "//button[contains(.,'Continue')]")
private WebElement PcoNoticeContinueBtn;//button to close the alert
*登录方式*
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");
我的方法:
//1.
if (PcoNoticeChbx!=null) {
PcoNoticeChbx.click();
PcoNoticeContinueBtn.click();
} else {
System.out.println("Dialog didn't display, no need any action");
}
//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. 添加到手表不起作用,它显示待处理,下面的代码也失败了。我在 Junit 中以调试模式运行我的 Maven。它曾经工作正常。但手表元素总是显示(待定)..
boolean isPresent = getDriver().findElements(By.id("noticebox")).size() >0
System.out.println("the diaolog exist= " + isPresent);
//4. 甚至尝试了try-catch方法。
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:
列表 temp = webdriver.findElements(org.openqa.selenium.By.id("noticebox"));
if (temp.Count > 0 && temp[0].Displayed) {
// script to execute if element is found
} else {
// continue the test
}
//6. 及以下
if (!WebDriver.findElements(By.xpath("//*[@id='submit']")).isEmpty()==true);
{
//handle the dialog
}
else{
//continue
}
// 7.tried 使用布尔值,但它也停留在这里的第一步
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();
}