【问题标题】:Py + SeleniumWebdriver - NoSuchElementException not workingPy + SeleniumWebdriver - NoSuchElementException 不起作用
【发布时间】:2021-02-13 18:46:28
【问题描述】:

我不明白为什么这不起作用?我知道这个页面上没有这样的元素,但是NoSuchElementException 没有被提出!

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Chrome("C:\\Users\\chromedriver.exe")
driver.get('https://www.kinopoisk.ru/')
try:
    driver.find_element_by_name('kp_query1')
except NoSuchElementException:
    print('WTF')
print('Ok!') 

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver webdriver nosuchelementexception


    【解决方案1】:

    更多关于您为什么觉得NoSuchElementException 没有上升的信息将有助于我们构建更规范的答案。


    但是,我拿走了你的代码,在执行时NoSuchElementException 被正确捕获,except{} 块被正确执行。

    • 代码块:

      driver.get('https://www.kinopoisk.ru/')
      try:
          driver.find_element_by_name('kp_query1')
      except NoSuchElementException:
          print('WTF')
      print('Ok!') 
      
    • 控制台输出:

      WTF
      Ok!
      

    【讨论】:

    • 有趣的事情 - 在我的 Ububtu 笔记本电脑上 - 它工作正常,一切正常!但在我的 Windows 电脑上 - 不工作!谢谢)
    猜你喜欢
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-02
    • 2017-07-29
    • 2016-03-27
    相关资源
    最近更新 更多