硒 - 下拉 - 蟒蛇

时间:2015-10-20 22:07:36

标签: python selenium selenium-webdriver web-scraping

<input id="clusteredDownloadButton" name="clusteredDownloadButton" type="submit" value="Download" onclick="submitForm('download',1,{source:'clusteredDownloadButton'});return false;" class="submit">

xpath: // * [@ id =“downloadClusterSelectOneChoice”]

<option value="">Select One</option>
<option value="0">PSI-MITAB 2.5</option>

xpath: // * [@ id =“downloadClusterSelectOneChoice”] /选项[2]

所以我需要选择PSI-MITLAB 2.5选项并下载此类文件

<input id="clusteredDownloadButton" name="clusteredDownloadButton" type="submit" value="Download" onclick="submitForm('download',1,{source:'clusteredDownloadButton'});return false;" class="submit">

xpath: // * [@ id =“clusteredDownloadButton”]

我从网上找到的任何东西都尝试过很多东西,它一直给我一个错误。请帮忙!

尝试代码:

码#1

driver.find_element_by_xpath('//*[@id="downloadClusterSelectOneChoice"]').click()
driver.select_by_visible_text("PSI-MITAB 2.5")

代码#2

driver.find_element_by_xpath('//*[@id="downloadClusterSelectOneChoice"]').click()
driver.find_element_by_xpath('//*[@id="downloadClusterSelectOneChoice"]/option[2]').click()

码#3

dropdown = driver.find_element_by_xpath('//*[@id="downloadClusterSelectOneChoice"]')
dropdown.select_by_value('PSI-MITAB 2.5')

码#4

dropdown = driver.find_element_by_xpath('//*[@id="downloadClusterSelectOneChoice"]/option[2]')
dropdown.select_by_value('PSI-MITAB 2.5')

所有人都不断抛出错误!

1 个答案:

答案 0 :(得分:0)

使用select_by_valueselect_by_index

dropdown = driver.find_element_by_xpath(dropdown_xpath)
dropdown.select_by_value('PSI-MITAB 2.5')