gpt4 book ai didi

python - Python 中的 Selenium : "NoSuchElementException: Message: no such element: Unable to locate element"

转载 作者:行者123 更新时间:2023-11-28 22:14:21 26 4
gpt4 key购买 nike

我尝试在第一个 id block 中键入“abc”,在第二个密码 block 中键入“cdef”。

但是,底部的错误代码出现了。

from selenium import webdriver
driver.get('http://sugang.korea.ac.kr')

我添加了隐式等待以防止代码在页面完全加载之前执行。

driver.implicitly_wait(30)

添加用户名和密码的代码如下:

driver.find_element_by_name('id').send_keys('abc')driver.find_element_by_name('pw').send_keys('cdef')

但我收到以下错误:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"id"}

最佳答案

“No Such Element”异常通常发生在 Web 驱动程序看不到您尝试对其执行操作的元素时。

原因可能是:

  1. 您的 ID 或名称或 XPath 或 CssSelector 可能是错误的。

  2. 您的元素可能位于 iframe 内,因此网络驱动程序无法看到或检测到它。 Switch to an iframe through Selenium and python

  3. 您的元素需要一些时间才能出现在 UI 上,因此您可以使用显式等待来解决此问题。参见 5. Waits

关于python - Python 中的 Selenium : "NoSuchElementException: Message: no such element: Unable to locate element",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53441658/

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