[英]How to handle pop up windows Java Selenium?
例如, TjMaxx
當用戶第一次導航時,彈出 window 出現,有時是 2,很難抓住並繼續前進。 我試過try catch,但它不起作用,因為它打開了一些我看不到的windows。 如何捕獲所有 windows 並為來賓用戶解除它們?
try {
WebElement closeWindowPromo = driver.findElement(By.xpath
("//div[@class =\"bx-row bx-row-submit bx-row-submit-no bx-row-2uaILGf bx-element-1360650-2uaILGf\"]//button[@data-click = 'close']"));
WebDriverWait w = new WebDriverWait(driver, 5);
w.until(ExpectedConditions.visibilityOfElementLocated((By) closeWindowPromo));
System.out.println("Element is visible");
} catch (NoSuchElementException n) {
System.out.println("Element is invisible");
}
wait = new WebDriverWait(driver, 10);
不要單擊關閉按鈕,而是嘗試單擊帶有文本的元素,因為我不希望免費送貨導致elementToBeClickable()
的WebDriverWait並且您可以使用以下任一Locator Strategies :
選擇器:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[class*='bx-row-submit-no'] > button.bx-button[data-click = 'close'][type='reset']"))).click();
xpath :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='bx-button' and @data-click = 'close'][@type='reset' and contains(., 'shipping')]"))).click();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.