gpt4 book ai didi

selenium - 如何处理 Selenium WebDriver 中的弹出窗口

转载 作者:行者123 更新时间:2023-12-04 10:30:46 25 4
gpt4 key购买 nike

我尝试了从警报到多个窗口处理程序的所有内容,但是当我们在初始阶段加载到网站下方时无法摆脱弹出窗口。

https://www.build.com/

你能帮我解决这个问题,让我访问上面的 URL 并处理弹出窗口,想立即关闭它。

谢谢
安 git

最佳答案

所需的元素在 Modal Dialog Box 内所以要定位/单击您必须为 element_to_be_clickable() 引发 WebDriverWait 的元素您可以使用以下任一 Locator Strategies :

解决方案

您需要引入 WebDriverWait 以使所需元素可点击,您可以使用以下任一解决方案:

  • 使用 CSS_SELECTOR :
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.close.js-modal-close. > span.close-icon"))).click()
  • 使用 XPATH :
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='close js-modal-close ']/span[@class='close-icon']"))).click()
  • 备注 :您必须添加以下导入:
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
  • 关于selenium - 如何处理 Selenium WebDriver 中的弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60427474/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com