简体   繁体   English

Python (Selenium) 从 HHPRED 中选择下拉列表

[英]Python (Selenium) Selecting a drop down list from HHPRED

I'm attempting to select drop down menu items from the HHPRED website.我正在尝试 select 从 HHPRED 网站下拉菜单项。 (URL: https://toolkit.tuebingen.mpg.de/tools/hhpred ) and I keep bumping into either 'object not found,' or 'object not clickable/selectable'. (网址: https://toolkit.tuebingen.mpg.de/tools/hhpred )我一直碰到“找不到对象”或“无法点击/选择对象”。

# 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.我知道我正在正确地处理 selenium,因为我的文本输入的第一部分正在正确复制,但是,当我从选择它到甚至选择我需要的东西的下拉菜单中工作时 - 我迷路了。 See below the inspected elements for HHPRED and the drop down I'm looking at tackling.请参阅下面检查的 HHPRED 元素和我正在处理的下拉列表。

在此处输入图像描述

在此处输入图像描述

Any help would be greatly appreciated!任何帮助将不胜感激!

Currently your url is unreachable due tooc credntials.目前,由于 tooc 凭证,您的 url 无法访问。 You can use below code to select value/visible text from the dropdown.您可以将以下代码用于 select 值/下拉列表中的可见文本。

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: Output:

在此处输入图像描述

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

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