如何在<select> Python中单击<option>

时间:2015-08-04 17:40:07

标签: python html selenium

我想通过id点击某个选项..问题是我所选择的选项之上 &lt; ul style =“display:block; visibility:visible;”&gt;&lt; li&gt;&lt; a href =“#”index =“0”class =“”onclick =“s_objectID =&amp; quot; https:/ /viajemais.voeazul.com.br/Contact.aspx#_573&quot;;return this.s_oc?this.s_oc(e):true“&gt; .... 这就是当我点击下拉按钮时可见的内容 而且我有选择 &lt; select id =“ControlGroupContact_ContactInputView_DropDownListStateProvince”name =“ControlGroupContact $ ContactInputView $ DropDownListStateProvince”readonly =“false”class =“jqTransformHidden”&gt;&lt; option selected =“”value =“”&gt; Escolha um&lt; / option&gt;                 &lt; option value =“BR | AC”&gt; Acre&lt; / option&gt; ... 我试过用这个代码: countries_dropdown = self.browser.find_element_by_class_name('countryBR')     countries_dropdown.click()     country_dropdown =选择(countries_dropdown.find_element_by_id('ControlGroupContact_ContactInputView_DropDownListCountry'))     country_dropdown.select_by_value(payer_details.country_code.upper()) 所以我甚至打开下拉列表,即使我打开,即使我不打开下拉列表,我得到的错误是 selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见:元素当前不可见,可能无法操作   (会话信息:chrome = 44.0.2403.125)   (驱动程序信息:chromedriver = 2.15.322448(52179c1b310fec1797c81ea9a20326839860b7d3),platform = Windows NT 6.3 x86_64)

1 个答案:

答案 0 :(得分:0)

看起来jqTransformHidden类隐藏了它。删除该类并使其可见:

dropdown = countries_dropdown.find_element_by_id('ControlGroupContact_ContactInputView_DropDownListCountry')
driver.execute_script("arguments[0].className = '';", dropdown)