0

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>

3 Answers 3

1

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)
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry how do I get the box? I tried getting the box element with driver.find_element_by_id("organism_text_input") but it didn't work.
@CPak There is an item with id "species_text" contained in the div with id "organism_text_input"
Where does Keys come from? Getting Keys is not defined error.
1
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()

5 Comments

After performing your steps and rescraping the page, I still see the original links. For instance, I expect to see 9606.protein_chemical.links.v5.0.tsv.gz . Could you extend your solution a few more steps to get the updated links? (Sorry, otherwise, I'm unable to validate whether it worked or not).
Perhaps the site is loading too slow, I've added an explicit wait for the drop down menu to load before proceeding. Either way the code is working as expected on my end.
After driver.find_element_by_class_name('minibutton').click(), how do I get the HTML of the updated page? driver.get(...)?
I can't write your entire project. Hopefully the answer I provided meets the requirements of the original question.
Haha, okay. Thanks for your help. I have already solved my own problem (see my answer). I wanted to expand on your answer for future users but that's okay.
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.