Utilizing Python's Selenium library to select data from a dropdown menu on HHPRED

Struggling to navigate the drop-down menu on the HHPRED website, I keep encountering 'object not found' or 'object not clickable/selectable' errors. (Website URL: )

# Inputting protein from a text file (using predator_file variable)
text_area = driver.find_element_by_id('__BVID__121')
text_area.send_keys(predator_file)

# Selecting 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_")

Although I believe I am using selenium correctly as the text input part is functioning, I am struggling with navigating and selecting options in the drop-down menu. Below are images of the inspected elements for HHPRED and the specific drop-down that is causing me difficulty.

https://i.stack.imgur.com/I6Q5O.jpg

https://i.stack.imgur.com/osbNd.jpg

Any assistance would be greatly appreciated!

Answer №1

Your URL is currently inaccessible due to credentials. To retrieve values or visible text from a dropdown, you can utilize the code snippet provided below.

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 include the necessary imports in 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

Alternatively,

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

Updated Solution: Since it's a custom dropdown element, handling it requires a different approach. Below is a code snippet for reference that has been tested and confirmed to work as intended.

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:

https://i.stack.imgur.com/HwQoO.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on leveraging Selenium to communicate with the login pop-up:

Seeking help with using Selenium to automate logging into a website and downloading financial reports. Find the link below: I understand how to handle login forms with attached IDs, but struggling with interacting with a pop-up login form through Selenium ...

Python with Odoo is throwing a SessionNotCreatedException with the message "session not created from tab crashed", while Selenium is functioning properly on its own

I am currently utilizing selenium integrated with Odoo 13 Here is the code I am using: driver = webdriver.Chrome('/home/dev/chromedriver') When running this code from an external Python file, it works perfectly fine. I even tested executing t ...

"Encountering a MoveTargetOutOfBoundsException error while using Selenium with Python

My Accounts Menu has a feature where the sub menus appear when the mouse hovers over it. Check out the screenshot below. I am trying to click on 'Accounts Summary' using my Selenium code shown below. def test_accounts(self): self.login(self ...

Activate a new browser tab with Selenium

Currently, I am utilizing Selenium with PhantomJS in Python to handle a new window. For the purpose of testing, my approach is as follows: from selenium import webdriver driver = webdriver.PhantomJS() driver.get('http://www.google.com.br') han ...

Capturing an image from a link in a Discord message using Discord.py

I'm in the process of developing a bot that can save links sent in messages automatically. When a user sends the command -save test.com/123.png, my bot is designed to download the file named 123.png. Although I have experience downloading directly at ...

Error encountered when executing Selenium WebDriver

Currently in the middle of an online Python course and making progress, but encountering a challenge with pulling HTML data. The TypeError that occurs every time the process finishes has me puzzled. I've followed the instructor's steps closely, y ...

inexperienced with selenium, unfamiliar with potential errors

Hello, I am a Python 3.6 beginner seeking assistance with my code and the error it's generating. I would greatly appreciate any help in identifying what is going wrong. Thank you. #!/usr/bin/env python #coding: utf-8 from selenium import webdriver ...

Python and Selenium are having trouble locating the search bar

My attempt to locate and interact with the first search box on the following website has been unsuccessful: This is the code I've used: for ii in testList2: varTitel = ii searchBox = driver.find_element_by_id('MainContent_SuchworteF ...

Running the endswith method

It appears that the if statement is not being executed, perhaps due to an error on my part. I attempted, ends = line.endswith('/') if (line.startswith(' ') and ends == True) However, it is not functioning as expected. The if statem ...

I am encountering a 404 error when attempting to make a GET request for a file located in the same directory

Here is the Javascript code that utilizes the get method. The directory contains both files - the HTML file where the JS code resides, and the text file. Below is an image of the console displaying errors. ...

Strategies for addressing the issue: SessionNotCreatedException occurs when a new session cannot be initiated. This error may be due to an incorrect remote server address

Hi everyone, I'm completely new to using Appium and testing in general. I'm currently experiencing an error that I am unsure how to resolve. Any help would be greatly appreciated. My goal is to test an application on my android studio emulator, ...

analyzing a snippet of HTML script using BeautifulSoup

As I attempt to gather data from a particular website, I have successfully identified the exact location of the required information. When inspecting the site in Chrome, I can see the specific data I need - in this case, the time. Here is an example of how ...

How can I effectively test a script using Python's Unittest and sys.argv to define global variables?

Looking to test a script that has the following structure: my_script.py import argparse, sys def my_parser(args=sys.argv[1:]): parser = argparse.ArgumentParser(description="my parser") parser.add_argument("--my-arg", dest="m ...

Getting specific values from a Pandas DataFrame using multiple conditions with df.loc

This particular section in the 1.1.4 version documentation is giving me trouble In [45]: df1 Out[45]: A B C D a 0.132003 -0.827317 -0.076467 -1.187678 b 1.130127 -1.436737 -1.413681 1.607920 c 1.024180 0.569605 0.87 ...

Exploring the Features and Functions of Google Chrome Through Selenium

Is it feasible to establish the Chrome homepage using capabilities and Chrome options within Selenium? ...

Capturing a series of values and storing them in a separate column using Python

I am dealing with a column ID that consists of either 10 numbers or 7 numbers. My goal is to create a new column that only includes the last 3 digits if the Column ID has a length of 10, and if it has a length of 7, then I want to keep the entire number. D ...

Having difficulty accessing hyperlink during execution of Selenium WebDriver script

I have been attempting to click on a hyperlink that is supposed to open a popup on the screen. However, I am encountering an issue as it is not working. Currently, the HTML code for the hyperlink looks like this: <a href="javascript:void(0)" class="ope ...

Is there a way to attach an audio file to a video clip using moviepy without having to re-encode the

I've been experimenting with the following code: from moviepy.editor import * videoclip = VideoFileClip("filename.mp4") audioclip = AudioFileClip("audioname.mp3") new_audioclip = CompositeAudioClip([audioclip]) videoclip.audio = n ...

Selenium is having trouble finding the iframe element

I'm struggling to locate the input element within an iframe using Selenium. Even after trying switchTo().frame(id) and switchTo().frame(index), I am still unable to find it. This is the code snippet I have been using: driver.switchTo().defaultConten ...

"Exploring Optimization with Python-mip and Enhancing Code with

Currently, I am utilizing Python with VSCode on Ubuntu. Despite having installed Python-mip and successfully running it in the terminal, VSCode seems to be unable to detect the mip library from Python-mip. Specifically, when I attempt to import necessary ...