简体   繁体   English

使用 Python Selenium 在下拉列表中单击选项

[英]Click on Option in Dropdown List using Python Selenium

I'm trying to update the page http://stitch.embl.de//cgi/download.pl?UserId=FCCY8Z7drB9z&sessionId=QFV3kq1R2gdD via Python-Selenium (emulating action of clicking on Choose an organism -> Homo sapiens , then click on Update )我正在尝试通过 Python-Selenium 更新页面http://stitch.embl.de//cgi/download.pl?UserId=FCCY8Z7drB9z&sessionId=QFV3kq1R2gdD (模拟点击Choose an organism -> Homo sapiens动作,然后点击在Update

How do I execute the script?如何执行脚本?

<div style="height:3em;vertical-align:top;"><div id="organism_text_input"><script type="text/javascript">
    function toggleSpeciesFloatingDiv ()
    {
        if(document.getElementById('speciesFloatingDiv').style.visibility != "visible") {
            initiateDropDownSpeciesList();
            document.getElementById('speciesFloatingDiv').style.display = "block";
            document.getElementById('speciesFloatingDiv').style.visibility = "visible";
            document.getElementById('speciesList').focus();
        } else {
            document.getElementById('speciesFloatingDiv').style.display = "none";
            document.getElementById('speciesFloatingDiv').style.visibility = "hidden";
        }
    }
</script>

You can click on the selector box ->你可以点击选择框->

box.click()

Then you can write the text and press enter ->然后您可以编写文本并按 Enter ->

box.send_keys("Homo Sapiens")
box.send_keys(Keys.RETURN)
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
delay = 10

driver.get("http://stitch.embl.de//cgi/download.pl?UserId=FCCY8Z7drB9z&sessionId=QFV3kq1R2gdD")

# CLick down arrow on drop down menu

WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, '//*[@id="organism_text_input"]/div[1]/div/img'))).click()
# driver.find_element_by_xpath().click()
# Now that options are loaded, select "Homo sapiens" from the species list
select = Select(driver.find_element_by_id('speciesList'))
select.select_by_visible_text('Homo sapiens')

# Click the 'Select' button in the drop down menu to apply
driver.find_element_by_class_name('minibutton').click()

I can get the desired links if I add &species_text=9606 to the URL - the final URL becomes http://stitch.embl.de//cgi/download.pl?UserId=FCCY8Z7drB9z&sessionId=QFV3kq1R2gdD&species_text=9606 I can get the desired links if I add &species_text=9606 to the URL - the final URL becomes http://stitch.embl.de//cgi/download.pl?UserId=FCCY8Z7drB9z&sessionId=QFV3kq1R2gdD&species_text=9606

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM