【问题标题】:How to use Close a dynamic Popup with python Selenium如何使用 python Selenium 关闭动态弹出窗口
【发布时间】:2021-06-21 07:40:17
【问题描述】:

我正在尝试关闭此弹出窗口,但我不能, 我试过使用find.element.by.xpath() 我猜有各种不同的可能性, 尝试使用switch_to _alert().dismiss() ,但似乎没有任何帮助 任何帮助深表感谢, 谢谢

【问题讨论】:

    标签: python python-3.x selenium selenium-chromedriver webdriverwait


    【解决方案1】:

    似乎不是 警报。它只是网页上的另一个元素。

    诱导WebDriverWait() 并等待element_to_be_clickable() 和后面的css选择器

    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div#dismiss-button"))).click()
    

    您需要导入以下库。

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    

    注意:如果出现超时错误,请检查元素是否在iframe 下。如果是这样,您需要切换到 iframe 才能与按钮元素进行交互。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 2020-06-22
      • 2018-08-21
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多