在頁面物件工廠中:
By popup=By.xpath("//button[test()='NO THANKS']");
public List<WebElement> getPopUpSize(){
return driver.findElements(popup);
}
public WebElement getPopUp(){
return driver.findElement(popup);
}
將上述方法呼叫到測驗用例中:
LandingPage l = new LandingPage(driver);
if(l.getPopUpSize().size()>0)
{
l.getPopUp().click();
}
我不明白為什么我們必須創建一個串列來取消單個彈出?
uj5u.com熱心網友回復:
不,您不需要findElements單個 Web 元素。改為使用findElement或Explicit waits如下圖所示:
- 使用
ExplicitWaits
代碼:
public WebElement getPopUpWebElement(){
return driver.findElement(popup);
}
在測驗方法中:
try {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.elementToBeClickable(getPopUpWebElement())).click();
}
catch(Exception e){
System.out.println("Could not click on pop up");
e.printStackTrace();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/463169.html
