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) 
    3
    • 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
      CommentedDec 14, 2020 at 17:34
    • @CPak There is an item with id "species_text" contained in the div with id "organism_text_input"
      – Atomium
      CommentedDec 14, 2020 at 17:40
    • Where does Keys come from? Getting Keys is not defined error.
      – CPak
      CommentedDec 14, 2020 at 17:49
    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
    • 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).
      – CPak
      CommentedDec 14, 2020 at 17:50
    • 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.
      – Chris
      CommentedDec 14, 2020 at 18:40
    • After driver.find_element_by_class_name('minibutton').click(), how do I get the HTML of the updated page? driver.get(...)?
      – CPak
      CommentedDec 14, 2020 at 20:31
    • I can't write your entire project. Hopefully the answer I provided meets the requirements of the original question.
      – Chris
      CommentedDec 14, 2020 at 21:00
    • 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.
      – CPak
      CommentedDec 14, 2020 at 21:45
    -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

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.