CPak
CPak

Reputation: 13581

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)

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>

Upvotes: 0

Views: 150

Answers (3)

Chris
Chris

Reputation: 16147

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()

Upvotes: 1

CPak
CPak

Reputation: 13581

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

Upvotes: -1

Atomium
Atomium

Reputation: 47

You can click on the selector box ->

box.click()

Then you can write the text and press enter ->

box.send_keys("Homo Sapiens")
box.send_keys(Keys.RETURN)

Upvotes: 1

Related Questions