繁体   English   中英

如何处理弹出 windows Java Selenium?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM