简体   繁体   English

使用Selenium和python从下拉菜单中选择一个选项

[英]seleting an option from a drop down menu using selenium and python

I'm having the following problem. 我遇到以下问题。 I have a dropdown that is hidden so when I make the Select and run the test i get the following error: 我有一个隐藏的下拉菜单,因此当我进行选择并运行测试时,出现以下错误:

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见:元素当前不可见,可能无法操作

below is the code i have been trying: 下面是我一直在尝试的代码:

cur=Select(driver.find_element_by_id("currencyCode"))
cur.select_by_visible_text('USD')

below is the html syntax of the code: 以下是代码的html语法:

<div class="form-group true-grid-3">
            <label for="currencyCode">Currency</label>
            <select id="currencyCode" name="criteria.currencyCode" class="form-control" style="display: none;">
                <option value="CHF">CHF</option>
                <option value="EUR">EUR</option>
                <option value="GBP">GBP</option>
                <option value="JPY">JPY</option>
                <option value="USD">USD</option>

设置display: nonedisplay: block中的CSS属性使得元件变得可见。

driver.execute_script("document.getElementById('criteria.currencyCode').style.display = 'block';")

您可以尝试调用下拉驱动程序driver.find_element_by_id("currencyCode").click() ,然后在显示选项时选择所需的选项driver.find_element_by_xpath('//option[@value="USD"]').click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Selenium选择下拉菜单选项 - Python Selenium Select Drop Down Menu Option 使用Selenium / Beautiful Soup- Python从“下拉菜单”中提取选项值 - Extract option values from 'drop down menu' using Selenium/Beautiful Soup- Python 使用selenium python从下拉选项中选择一个值 - Selecting a value from a drop-down option using selenium python 如何使用 Selenium 和 Python 从下拉菜单中的 select 项目? - How to select item from drop down menu using Selenium with Python? 在python中使用硒从下拉菜单中选择多个选项 - Selecting multiple options from drop down menu using selenium in python Selenium-Python-Javascript下拉菜单选项值 - Selenium - Python - Javascript drop-down menu option value Python-硒-在下拉菜单中循环-选项不可见 - Python - Selenium - Cycling through drop-down menu - Option not visible Selenium 有没有办法从谷歌表单(python)的下拉菜单中选择一个选项 - Is there a way in Selenium to select an option from a drop down menu in google forms (python) Python:如何从Selenium的下拉菜单中选择选项,元素已隐藏 - Python: How to select option from drop down menu in Selenium, element hidden 如何使用Selenium - Python选择下拉菜单选项值 - How to select a drop-down menu option value using Selenium - Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM