Python splinter. How to select dropdown list which doesn't have name in option section -


i try select "local host" dropdown list has following html code:

    <select id="server_select">   <option></option>     <option>      local host   </option>     <option>      ah005   </option>  </select> 

here python code use splinter module select ah005 dropdown list failed.

    server_list = browser.find_by_xpath('//select[@id="server_select"]//option[@selected="local host"]').first     server_list.click() 

and got error:

 traceback (most recent call last):   file "splinter_test.py", line 22, in <module>     server_list = browser.find_by_xpath('//select[@id="server_select"]//option[@selected="local host"]').first   file "/users/bibo_mbpr/anaconda/lib/python2.7/site-packages/splinter/element_list.py", line 53, in first     return self[0]   file "/users/bibo_mbpr/anaconda/lib/python2.7/site-packages/splinter/element_list.py", line 44, in __getitem__     self.find_by, self.query)) splinter.exceptions.elementdoesnotexist: no elements found xpath "//select[@id="server_select"]//option[@selected="local host"]" 

could please give me advice? thanks

named options helpful. when don't exist have iterate on options find right one.

dropdown = browser.find_by_xpath("//select[@id='server_select']")  option in dropdown.find_by_tag('option'):     if option.text == "local host":         option.click()         break 

you may need call strip() on option.text before comparing in case contains whitespaces.

and in case empty option @ top causing problems change if case option.text not none , option.text == "local host".


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -