#๐Ÿ”’ Encountering an unusual error while working with selenium.

18 messages ยท Page 1 of 1 (latest)

half yarrow
#
    select_element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, ".DropDown_select__4pIg9"))
    )
    
    selected = Select(select_element)
    selected.select_by_value("-1")

The error is as follows:
An unexpected error occurred while scraping season 2000-01: Message: Cannot locate option with value: -1; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception

This is weird because, I extracted the value "-1" from the website itself.

<select name="" class="DropDown_select__4pIg9"><option value="-1">All</option><option value="0">1</option><option value="1">2</option><option value="2">3</option><option value="3">4</option><option value="4">5</option><option value="5">6</option><option value="6">7</option><option value="7">8</option><option value="8">9</option></select>
<option value="8">9</option>
<option value="7">8</option>
<option value="6">7</option>
<option value="5">6</option>
<option value="4">5</option>
<option value="3">4</option>
<option value="2">3</option>
<option value="1">2</option>
<option value="0">1</option>
<option value="-1">All</option>
<select name="" class="DropDown_select__4pIg9"><option value="-1">All</option><option value="0">1</option><option value="1">2</option><option value="2">3</option><option value="3">4</option><option value="4">5</option><option value="5">6</option><option value="6">7</option><option value="7">8</option><option value="8">9</option></select>
frail cypressBOT
#

@half yarrow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

stable tapir
#

My guess is that you're either grabbing the wrong <select> element (since there might be duplicates) or the options didnt load by the time you try to select one. Try waiting for the option[value="-1"] to be shown instead of just the dropdown @half yarrow

half yarrow
stable tapir
#

Just make sure your either reduce it by looping through the matches to pick the right innerHTML

#

and np

half yarrow
#

Ahh. I didn't know you could loop through the matches. Thankyou

#

i'll try that

#

umm @stable tapir How would loop through the matches? I couldn't find anything that returns an iterable of matches. It just seems to return the first match it finds.

stable tapir
#

You can use find_elements instead of find_element

#

Basically your checking each one to see if it has the option you needand once you find the right one it will wrap it with Select()

half yarrow
#

ahh ok got it.

#

thankyou

stable tapir
#

nppp

half yarrow
#

Welp now why exactly is it saying this?

 self._set_selected(opt)
    ~~~~~~~~~~~~~~~~~~^^^^^
  File "/Users/inheritanc-e/.local/share/virtualenvs/pet_projects-K3ru-czp/lib/python3.13/site-packages/selenium/webdriver/support/select.py", line 214, in _set_selected
    option.click()
    ~~~~~~~~~~~~^^
  File "/Users/inheritanc-e/.local/share/virtualenvs/pet_projects-K3ru-czp/lib/python3.13/site-packages/selenium/webdriver/remote/webelement.py", line 119, in click
    self._execute(Command.CLICK_ELEMENT)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/inheritanc-e/.local/share/virtualenvs/pet_projects-K3ru-czp/lib/python3.13/site-packages/selenium/webdriver/remote/webelement.py", line 572, in _execute
    return self._parent.execute(command, params)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/inheritanc-e/.local/share/virtualenvs/pet_projects-K3ru-czp/lib/python3.13/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
    self.error_handler.check_response(response)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/inheritanc-e/.local/share/virtualenvs/pet_projects-K3ru-czp/lib/python3.13/site-packages/selenium/webdriver/remote/errorhandler.py", line 232, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: 

And how do i get around it?

half yarrow
#

!close

frail cypressBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.