gpt4 book ai didi

python - 无法使用 Selenium 关闭弹出框

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:57 26 4
gpt4 key购买 nike

我无法使用 Selenium 关闭弹出框。下面是我编写的代码,它返回一个异常。请参阅下面的代码。

driver = webdriver.Chrome()
driver.get("https://www.google.com/webhp#q=home+depot+san+francisco&lrd=0x808f7c5c63124c7b:0x32c19e9988b2aa90,1,")
driver.find_element_by_xpath('//div[@class="_wzh"]').click()
# selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

谢谢

最佳答案

打开弹出窗口需要一些时间。因此,您需要等待几秒钟,直到弹出窗口打开并显示关闭按钮。

用户显式等待条件,直到元素可见,如下所示:

element = WebDriverWait(driver, 60).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "div>._wzh"))
)
element.click()

关于python - 无法使用 Selenium 关闭弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44296273/

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