目標:警報彈出。無論是否顯示,我希望它繼續。如果顯示,則必須選中複選框,然後按繼續。如果不是,則忽略。硒的Java處理對象(警報對話框)異常而不會延遲。 (預見的Java彈出)
攔截器:如果警報顯示,它將處理該操作並且對話框將被關閉。但是當硒沒有顯示時,硒懸掛在那裏,沒有處理條件。
背景:我之前使用UFT,也許我的邏輯可能是錯誤的。 彈出的應用程序的警報(不繫統),所以假定「切換到(),接受()/駁回()將無法工作。我將添加手柄警報登錄之後,和下方的登錄方法中。
硒框架背景:我們使用硒行家框架,平靜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:
列表臨時= 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。試圖用布爾值,而且還掛在這裏的第一個步驟
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();
}
當使用try catch代碼時,它採用了:元素不可點擊。 –
public void checkAlert(){ \t try { \t WebDriverWait wait = new WebDriverWait(getDriver(),2); \t System.out.println(「TRYing steps」); \t wait.until(ExpectedConditions.alertIsPresent()); \t org.openqa.selenium.Alert alert = getDriver()。switchTo()。alert(); \t alert.accept(); \t \t // \t}趕上(例外五){ \t //異常處理 \t \t System.out的。println(「catch exception steps」); \t} \t \t} \t } –