【问题标题】:How can I check if element exists, close selenium driver if it does and if it doesn't continue with the script in Python [closed]如何检查元素是否存在,如果存在则关闭 selenium 驱动程序,如果它不继续使用 Python 中的脚本 [关闭]
【发布时间】:2021-01-23 17:55:27
【问题描述】:

如何检查元素是否存在,如果存在则关闭驱动程序,如果它不继续 Python 中的脚本

类似

driver.findElement(webdriver.By.id('*****'));
close.driver()

正是标题所说的。

【问题讨论】:

  • 请提供一些信息,说明您已经尝试过什么以及到目前为止出了什么问题。也可以考虑stackoverflow.com/help/how-to-ask
  • 对不起,我是新手。我们都从某个地方开始:)

标签: python if-statement element exists


【解决方案1】:

像这样使用 'try' 和 'except' 怎么样:

try: driver.findElement(webdriver.By.id('*****'))
except: driver.close()

【讨论】:

  • 谢谢你的回复,可惜这没用.....啊,应该是driver.close()
  • 对不起,我忽略了那部分。更新。现在可以用了吗?
  • @juniper25 如果您满意,请接受答案吗?我也是新来的,正在努力建立声誉。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-16
相关资源
最近更新 更多