--------------------------------------------------------------------------- NoSuchElementException Traceback …
- User
NoSuchElementException Traceback (most recent call last) Cell In[8], line 6 3 filter_button.click() 5 # Locate the desired option by its text and click it ----> 6 desired_option = driver.find_element(By.XPATH, "//span[contains(text(), 'Кредиторы')]") 7 desired_option.click()
File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py:741, in WebDriver.find_element(self, by, value) 738 by = By.CSS_SELECTOR 739 value = f'[name="{value}"]' --> 741 return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\webdriver.py:347, in WebDriver.execute(self, driver_command, params) 345 response = self.command_executor.execute(driver_command, params) 346 if response: --> 347 self.error_handler.check_response(response) 348 response["value"] = self._unwrap_value(response.get("value", None)) 349 return response
File ~\AppData\Local\anaconda3\Lib\site-packages\selenium\webdriver\remote\errorhandler.py:229, in ErrorHandler.check_response(self, response) 227 alert_text = value["alert"].get("text") 228 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here --> 229 raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(text(), 'Кредиторы')]"} (Session info: chrome=119.0.6045.160); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception Stacktrace: GetHandleVerifier [0x00007FF6255182B2+55298] (No symbol) [0x00007FF625485E02] (No symbol) [0x00007FF6253405AB] (No symbol) [0x00007FF62538175C] (No symbol) [0x00007FF6253818DC] (No symbol) [0x00007FF6253BCBC7] (No symbol) [0x00007FF6253A20EF] (No symbol) [0x00007FF6253BAAA4] (No symbol) [0x00007FF6253A1E83] (No symbol) [0x00007FF62537670A] (No symbol) [0x00007FF625377964] GetHandleVerifier [0x00007FF625890AAB+3694587] GetHandleVerifier [0x00007FF6258E728E+4048862] GetHandleVerifier [0x00007FF6258DF173+4015811] GetHandleVerifier [0x00007FF6255B47D6+695590] (No symbol) [0x00007FF625490CE8] (No symbol) [0x00007FF62548CF34] (No symbol) [0x00007FF62548D062] (No symbol) [0x00007FF62547D3A3] BaseThreadInitThunk [0x00007FFD0FF3257D+29] RtlUserThreadStart [0x00007FFD1170AA78+40]
- Assistant
The NoSuchElementException occurs because the element with the XPath "//span[contains(text(), 'Кредиторы')]" cannot be found on the webpage.
To resolve this issue, you can try the following solutions:
-
Verify that the XPath is correct: Double-check the XPath value and ensure that it correctly identifies the desired element on the webpage.
-
Check if the element is within an iframe: If the element is within an iframe, you need to switch to the iframe before locating the element. Use the
driver.switch_to.frame()method to switch to the desired iframe and then locate the element. -
Wait for the element to be visible: It is possible that the element is not yet visible on the webpage when the
find_element()method is called. In that case, you can use an explicit wait before locating the element. For example, you can use the class and the Expected Condition to wait for the element to become visible.
-