[英]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: none
至display: 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.