【问题标题】:how to handle popup in selenium webdriver (which is not alert)?如何处理 selenium webdriver 中的弹出窗口(不警报)?
【发布时间】:2015-12-16 07:17:01
【问题描述】:

2) 弹出窗口显示输入电子邮件地址进行注册。

3) 由于它不是弹出窗口,我无法导航到窗口

我尝试使用警报、javascriptexecutor 和窗口句柄但不起作用。有没有人建议如何处理它?

【问题讨论】:

  • 根据百思买政策,Unless we separately give you permission, you may not copy, scrape, frame, modify, remove, delete, augment, add to, publish, transmit, participate in the transfer or sale, lease or rental of, create derivative works from, or in any way exploit any of the Content, in whole or in part. 所以你不应该抓取他们的网站。将此问题标记为删除。
  • 它是一个模态弹出窗口。它不需要任何 switchTo()。只需添加 .implicitlyWait(推荐)或 sleep

标签: java selenium selenium-webdriver


【解决方案1】:

这不是弹出窗口。像查找页面上的任何其他元素一样查找它。

例如,您可以通过以下方式找到“关闭”按钮并单击它:

WebDriverWait wait = WebDriverWait(driver, 10);
WebElement closeButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.modal button.close")));
closeButton.click();

请注意,我们使用WebDriverWait 显式等待机制来等待关闭按钮变为可见。

【讨论】: