繁体   English   中英

Selenium 中的 selenium.common.exceptions.NoSuchElementException

[英]selenium.common.exceptions.NoSuchElementException in Selenium

我正在尝试让 Selenium 自动在 Chrome 中打开网页。 这是我的代码...

from selenium import webdriver


driver = webdriver.Chrome()


driver.get("https://www.python.org/")


element = driver.find_element_by_link_text("q")


print(element.click())

这是错误...

selenium.common.exceptions.NoSuchElementException

请帮忙。

我看到这里有两个问题:

  1. 您必须在element = driver.find_element_by_link_text("q")之前添加延迟才能让页面加载。
    最好您应该为此使用visibility_of_element_located预期条件。
  2. 我在那里没有看到链接文本等于q的元素

@Xman 的答案很简单。

selenium.common.exceptions.NoSuchElementException   

错误意味着元素错误/不存在。

element = driver.find_element_by_link_text("q")

也许没有称为“q”的元素。 再次检查它,然后输入元素。 希望这有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM