gpt4 book ai didi

python - 如何处理 splinter (python) 中的 Selenium 异常?

转载 作者:行者123 更新时间:2023-12-01 07:45:11 25 4
gpt4 key购买 nike

有时,当我尝试单击某个按钮时,它被另一个元素覆盖,并且我收到 selenium.common.exceptions.ElementClickInterceptedException。这种情况很少发生,也没什么大不了的,所以我想忽略它并继续前进,而不是退出脚本。

我试过了

除了 selenium.common.exceptions.ElementClickInterceptedException 作为 c:

除了 ElementClickInterceptedException 作为 c:

我假设两者都会抛出错误,因为我没有直接导入selenium,而是使用了splinter:NameError:name'ElementClickInterceptedException'未定义

我的代码示例:

if browser.is_element_present_by_css('a.User', wait_time=15):
try:
browser.find_by_css('a.User').first.click()
except ElementClickInterceptedException as c:
pass

使用 splinter 时如何处理 selenium 抛出的错误?

最佳答案

尝试使用 javascript 进行点击。

browser.execute_script("arguments[0].click()", browser.find_by_css('a.User').first)

关于python - 如何处理 splinter (python) 中的 Selenium 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56498379/

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