繁体   English   中英

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

[英]Weird Python Selenium error message when asked to find an element

我试图通过 class 使用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始终接受single class value不是multiple class values

而是使用 css 选择器。

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

暂无
暂无

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

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