【问题标题】:How to click on <option> inside <select> Python如何在 <select> Python 中单击 <option>
【发布时间】:2015-08-04 17:40:06
【问题描述】:

我想通过 id 点击某个选项.. 问题在我的选择上面

<ul style="display: block; visibility: visible;"><li><a href="#" index="0" class="" onclick="s_objectID=&quot;https://viajemais.voeazul.com.br/Contact.aspx#_573&quot;;return this.s_oc?this.s_oc(e):true">....

当我单击下拉按钮时,这就是可见的 比我有选择

<select id="ControlGroupContact_ContactInputView_DropDownListStateProvince" name="ControlGroupContact$ContactInputView$DropDownListStateProvince" readonly="false" class="jqTransformHidden"><option selected="" value="">Escolha um</option>
                <option value="BR|AC">Acre</option>...

我已经尝试使用该代码:

countries_dropdown = self.browser.find_element_by_class_name('countryBR')
    countries_dropdown.click()
    country_dropdown = Select(countries_dropdown.find_element_by_id('ControlGroupContact_ContactInputView_DropDownListCountry'))

    country_dropdown.select_by_value(payer_details.country_code.upper())

所以即使我打开下拉菜单,我什至会打开下拉菜单,即使我不打开下拉菜单,我得到的错误是

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated
  (Session info: chrome=44.0.2403.125)
  (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.3 x86_64)

【问题讨论】:

    标签: python html selenium


    【解决方案1】:

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

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

    【讨论】:

    • 现在我可以点击,但它似乎并没有真正点击,因为下拉菜单保持打开状态并且状态下拉菜单为空
    • @DorAlt btw,您是否尝试过先单击下拉菜单将其打开,然后单击一个选项?
    • 当您意识到复制粘贴而不是更改某些内容并删除某些内容的那一刻?这就是发生的事情,我从昨天开始就坐在上面谢谢你
    猜你喜欢
    • 1970-01-01
    • 2012-03-03
    • 2021-08-27
    • 2021-04-27
    • 2020-08-19
    • 1970-01-01
    • 2019-02-09
    • 2014-05-05
    • 2020-09-28
    相关资源
    最近更新 更多