Selenium从下拉列表中选择Python
我在python中使用selenium,我希望从以下选项中选择男性:Selenium从下拉列表中选择Python,python,selenium,drop-down-menu,google-chrome-devtools,Python,Selenium,Drop Down Menu,Google Chrome Devtools,我在python中使用selenium,我希望从以下选项中选择男性: <div class="formelementcontent"> <select aria-disabled="false" class="Width150" id="ctl00_Gender" name="ctl00$Gender" onchange="javascript: return doSearch();" style="display: none;">
<div class="formelementcontent">
<select aria-disabled="false" class="Width150" id="ctl00_Gender" name="ctl00$Gender" onchange="javascript: return doSearch();" style="display: none;">
<option selected="selected" title="" value="">
</option>
<option title="Male" value="MALE">
Male
</option>
<option title="Female" value="FEM">
Female
</option>
</select>
我尝试了许多选择,并进行了广泛的搜索。这让我大部分时间都很紧张
driver.find_element_by_id("ctl00_Gender-button").click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "ctl00_Gender")))
select=Select(driver.find_element_by_id("ctl00_Gender"))
check=select.select_by_visible_text('Male')
如果我使用WebDriverWait,它会超时
我尝试过通过可见文本和索引进行选择,两者都提供:
ElementNotInteractiableException:无法将元素滚动到视图中
尝试以下解决方案:
解决方案1:
select = Select(driver.find_element_by_id('ctl00_Gender'))
select.select_by_value('MALE')
driver.find_element_by_xpath("//select[@id='ctl00_Gender']/option[text()='Male']").click()
注意将以下导入添加到您的解决方案中:
from selenium.webdriver.support.ui import Select
解决方案2:
select = Select(driver.find_element_by_id('ctl00_Gender'))
select.select_by_value('MALE')
driver.find_element_by_xpath("//select[@id='ctl00_Gender']/option[text()='Male']").click()
根据您共享的HTML,
标记的style属性值设置为显示:无代码>
。因此,使用它将很难与此交互
如果您通过访问网页的,可能会在
节点中找到与
节点等效的两个
节点。你可能需要与这些人互动
您可以在以下内容中找到一些相关的详细讨论: