1

I've lurked here for quite a while and gotten a lot of help from other questions but am having trouble finding a solution to the following. I am trying to select 225 from the following dropdown:

<pre><div class="controls controls-select"></pre>
     <select name="duration" class="input-medium"><option value="" selected="selected"></option><option value="225">225 minutes</option></select><br>
    <p class="help-block" id="reservations-checkout-date" style="display: none;"></p>
</div>

Using the following code:

duration = Select(browser.find_element_by_name('duration'))
duration.select_by_value('225')

However, I get this error.

Traceback (most recent call last):
  File "C:/Users/bfarlow/AppData/Local/Programs/Python/Python37-32/pool.py", line 33, in <module>
    duration = Select(browser.find_element_by_name('duration'))
  File "C:\Users\bfarlow\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 496, in find_element_by_name
    return self.find_element(by=By.NAME, value=name)
  File "C:\Users\bfarlow\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "C:\Users\bfarlow\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\bfarlow\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, 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":"[name="duration"]"}
  (Session info: chrome=81.0.4044.138)

Thanks for taking a look and I apologize for any formatting errors.

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
bf1985
  • 11
  • 1
  • Where is the function `browser.find_element_by_name` coming from? According to the error message it seems that it tries to find your element via CSS. If so, it's obvious that it can't be found. So you should probably use another selector function. – ahuemmer May 19 '20 at 18:00
  • See this https://stackoverflow.com/questions/11736027/webdriver-wait-for-element-using-java – Tarun Lalwani May 19 '20 at 18:00
  • Sorry - this is the error I get when using name. I've tried many selectors w/o much luck. File "C:\Users\bfarlow\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, 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":"[name="duration"]"} (Session info: chrome=81.0.4044.138) – bf1985 May 19 '20 at 18:06
  • Thank you, Tarun. That solved it! – bf1985 May 19 '20 at 18:09

0 Answers0