I need to select an element from a dropdown list using selenium webdriver in Python. For that I have checked helpful posts such as Selecting a value from a drop-down option using selenium python and https://sqa.stackexchange.com/questions/12029/how-do-i-work-with-dropdowns-in-selenium-webdriver?lq=1.
The element i am talking about is shown in the next block:
<div id="dayTab" style="height:20px" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
<select class="input-small input-thin">
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
</select>
</div>
I tried Select()
:
yearselect = Select(browser.find_element_by_css_selector("select.input-small.input-thin"))
yearselect.select_by_value("2010")
Although it locates the element (which it does), i then get the following error which occurs for the second line:
Traceback (most recent call last):
File "C:\Users\elek2\workspace\webdriving\src\gotonch.py", line 119, in <module>
yearselect.select_by_value("2010")
File "C:\Python34\lib\site-packages\selenium\webdriver\support\select.py", line 79, in select_by_value
self._setSelected(opt)
File "C:\Python34\lib\site-packages\selenium\webdriver\support\select.py", line 195, in _setSelected
option.click()
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 74, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 453, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated
(Session info: chrome=45.0.2454.101)
(Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.1 SP1 x86_64)
I am not sure why this happens but i have also tried to use Click()
instead in order to "open" the drop down list
yearselect =browser.find_element_by_css_selector("select.input-small.input-thin").click()
yearselect.select_by_value("2010")
and that the elements are visible but then I get this:
Traceback (most recent call last):
File "C:\Users\elek2\workspace\webdriving\src\gotonch.py", line 118, in <module>
yearselect = browser.find_element_by_css_selector("select.input-small.input-thin").click()
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 74, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 453, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=45.0.2454.101)
(Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 6.1 SP1 x86_64)
Why is element still not visible if I am able to locate the drop-down list and select it?
EDIT:
After LINGS comment I realised that there is not only one element with the css name that I 've used.
I am after the above block but there is another block referenced before that one where instead of div id="dayTab"...
is div id="monthTab"...
which obviously is invisible. How can I refer to the tab that I want, there's no ID.