简体   繁体   中英

Python (Selenium) Selecting a drop down list from HHPRED

I'm attempting to select drop down menu items from the HHPRED website. (URL: https://toolkit.tuebingen.mpg.de/tools/hhpred ) and I keep bumping into either 'object not found,' or 'object not clickable/selectable'.

# Input protein from txt file (predator_file variable)
text_area = driver.find_element_by_id('__BVID__121')
text_area.send_keys(predator_file)

# Input PDB, SCOP, PFAM, and NCBI domains

 first_click = driver.find_element_by_id('__BVID__130')
 scop_click = driver.find_element_by_link_text("SCOPe")
 pfam_click = driver.find_element_by_link_text("Pfam")
 ncbi_click = driver.find_element_by_link_text("ncbi_")

I know I'm working on selenium correctly because the first portion for my text entry is copying correctly but, when I'm working on the drop down from selecting it to even picking what I need - I'm lost. See below the inspected elements for HHPRED and the drop down I'm looking at tackling.

在此处输入图像描述

在此处输入图像描述

Any help would be greatly appreciated!

Currently your url is unreachable due tooc credntials. You can use below code to select value/visible text from the dropdown.

from selenium import webdriver
from selenium.webdriver.support.ui import Select 

select= WebDriverWait(driver, 30).until(
            EC.element_to_be_clickable((By.XPATH, "select element xpath")))

print(len(select.options))
select.select_by_value("")          # select by value
select.select_by_visible_text('')  # select by visible text

Note: please add below imports to your solution

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

or

driver.find_element_by_xpath("//select[@name='element_name']/option[text()='option_text']").click()

Updated solution : its a custom dropdown element so you need to handle it in a differnt way. Kindly find below code for your reference. I have verified it and its working as expected.

driver.get("https://toolkit.tuebingen.mpg.de/tools/hhpred")
main_window = driver.current_window_handle
wait = WebDriverWait(driver, 20)

wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn sign-in-link btn-href btn-sm']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "(//fieldset[@class='form-group']//input)[2]"))).send_keys('')
wait.until(EC.element_to_be_clickable((By.XPATH, "(//fieldset[@class='form-group']//input)[3]"))).send_keys('')
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-secondary']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'Got it!')]"))).click()

print wait.until(EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'Paste Example')]"))).text
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
clickElement=wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='multiselect__tags']")))
ActionChains(driver).move_to_element(clickElement).click().perform()
wait.until(EC.element_to_be_clickable((By.XPATH, "//li[*]//span[contains(text(),'TIGRFAMs_v15.0')]"))).click()

Output:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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