简体   繁体   English

Selenium 中的 selenium.common.exceptions.NoSuchElementException

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

I am trying to make Selenium automatically open a webpage in Chrome.我正在尝试让 Selenium 自动在 Chrome 中打开网页。 This is my code...这是我的代码...

from selenium import webdriver


driver = webdriver.Chrome()


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


element = driver.find_element_by_link_text("q")


print(element.click())

This is the error...这是错误...

selenium.common.exceptions.NoSuchElementException

Pls help.请帮忙。

I see there are 2 problems here:我看到这里有两个问题:

  1. You have to add delay before element = driver.find_element_by_link_text("q") to let the page load.您必须在element = driver.find_element_by_link_text("q")之前添加延迟才能让页面加载。
    Preferably you should use visibility_of_element_located expected condition for this.最好您应该为此使用visibility_of_element_located预期条件。
  2. I see no element with link text equals to q there我在那里没有看到链接文本等于q的元素

The answer @Xman is simple. @Xman 的答案很简单。

selenium.common.exceptions.NoSuchElementException   

error means that the element is wrong/doesn't exist.错误意味着元素错误/不存在。

element = driver.find_element_by_link_text("q")

maybe there is no element called "q".也许没有称为“q”的元素。 Do check it again and then enter the element.再次检查它,然后输入元素。 Hope this helped:)希望这有帮助:)

暂无
暂无

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

相关问题 selenium.common.exceptions.NoSuchElementException - selenium.common.exceptions.NoSuchElementException selenium.common.exceptions.NoSuchElementException:消息: - selenium.common.exceptions.NoSuchElementException: Message: 如何修复selenium.common.exceptions.NoSuchElementException? - How to fix selenium.common.exceptions.NoSuchElementException? “错误:selenium.common.exceptions.NoSuchElementException:消息 - "Error: selenium.common.exceptions.NoSuchElementException: Message Selenium 使用 Chrome 时出现“selenium.common.exceptions.NoSuchElementException” - Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome Selenium.common.exceptions.NoSuchElementException 错误,即使显式等待 - Selenium.common.exceptions.NoSuchElementException error even with explicit waiting 动态内容中的selenium.common.exceptions.NoSuchElementException - selenium.common.exceptions.NoSuchElementException from dynamic content selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素 - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素: - selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: 如何修复“selenium.common.exceptions.NoSuchElementException” - How can I fix "selenium.common.exceptions.NoSuchElementException"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM