python - 当要求查找元素时出现奇怪的 Python Selenium 错误消息

标签 python selenium selenium-webdriver

我尝试使用 startButton = driver.find_element(By.CLASS_NAME, "start is-armed") 按类查找元素,但收到一条非常奇怪的错误消息。最后看起来几乎可以是汇编语言:

[23248:27252:0126/162232.236:ERROR:device_event_log_impl.cc(215)] [16:22:32.235] USB: usb_service_win.cc:415 Could not read device interface GUIDs: The system cannot find the file specified. (0x2)
[23248:27252:0126/162232.237:ERROR:device_event_log_impl.cc(215)] [16:22:32.238] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Traceback (most recent call last):
  File "c:\Users\[myname]\OneDrive\Documents\Coding Projects\Python\learningSelenium.py", line 11, in <module>
    startButton = driver.find_element(By.CLASS_NAME, "start is-armed")
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[myname]\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 830, in find_element 
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\[myname]\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute      
    self.error_handler.check_response(response)
  File "C:\Users\[myname]\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".start is-armed"}
  (Session info: chrome=109.0.5414.120)
Stacktrace:
Backtrace:
        (No symbol) [0x00F96643]
        (No symbol) [0x00F2BE21]
        (No symbol) [0x00E2DA9D]
        (No symbol) [0x00E61342]
        (No symbol) [0x00E6147B]
        (No symbol) [0x00E98DC2]
        (No symbol) [0x00E7FDC4]
        (No symbol) [0x00E96B09]
        (No symbol) [0x00E7FB76]
        (No symbol) [0x00E549C1]
        (No symbol) [0x00E55E5D]
        GetHandleVerifier [0x0120A142+2497106]
        GetHandleVerifier [0x012385D3+2686691]
        GetHandleVerifier [0x0123BB9C+2700460]
        GetHandleVerifier [0x01043B10+635936]
        (No symbol) [0x00F34A1F]
        (No symbol) [0x00F3A418]
        (No symbol) [0x00F3A505]
        (No symbol) [0x00F4508B]
        BaseThreadInitThunk [0x762E7D69+25]
        RtlInitializeExceptionChain [0x77B0BB9B+107]
        RtlClearBits [0x77B0BB1F+191]

有人知道为什么会发生这种情况吗?

最佳答案

By.CLASS_NAME 始终接受单个类值,而不是多个类值

请使用 css 选择器。

startButton = driver.find_element(By.CSS_SELECTOR, ".start.is-armed")

关于python - 当要求查找元素时出现奇怪的 Python Selenium 错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75252277/

相关文章:

selenium - getAttribute 未返回 selenium 中样式的完整值

python - 自定义用户模型 Django 错误,没有这样的表

python - 测试 Django 内联模型表单 : How to arrange POST data?

python - 我可以向量化这个二维数组索引,其中第二维取决于第一维的值吗?

c# - 我为什么可以将 IWebDriver 转换为 IJavaScriptExecutor?

java - 测试未在 maven java 中运行

java - 如何在 Selenium WebDriver 的属性文件中使用多行属性?

python - Neo4j 使用 py2neo 从 pandas dataframe 创建节点和关系

selenium - WebDriver - Internet Explorer 中的关键命令

python - 一种使用 Selenium 检查复选框的有效方法