Home > Enterprise >  Weird Python Selenium error message when asked to find an element
Weird Python Selenium error message when asked to find an element

Time:01-27

I tried to find an element by class using startButton = driver.find_element(By.CLASS_NAME, "start is-armed") and I got a very weird error message. The end almost looks like it could be assembly language:

[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]

Anyone know why this is happening?

CodePudding user response:

By.CLASS_NAME always accept single class value NOT multiple class values.

Instead use css selector.

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