Use selenium to click link based on [python] input
I made a program with selenium to go to my schools website, login and get all the text using a CSS selector and print it. It then prints out all available exams. However, there is a download link next to each exam, and I am trying to create an input with an exam name, and then make a selenium click on that particular download button connected to that exam.
I don't know much about HTML, so I'll try to be as clear as I can.
Here's the code and some images:
from selenium import webdriver
browser = webdriver.Chrome('/usr/local/bin/chromedriver')
browser.get('https://minatentor.hv.se/minatentor/')
username = browser.find_element_by_css_selector('#userNameInput')
password = browser.find_element_by_css_selector('#passwordInput')
username.send_keys(r"my_username")
password.send_keys('my_password')
password.submit()
tentor = browser.find_element_by_css_selector('#examTable > tbody')
print(tentor.text)
browser.close()
This is the look and feel of the website. I used a CSS selector to get this text and print it ( '#examTable > tbody'
).
This is what it prints to the shell.
This is what the inspector looks like.
I used a CSS selector <tbody>
to get all the text. Each <tr>...</tr>
is a line marked in the picture. "Hรคmta" means "Download" in Swedish, so it's a download button.
I want to be able to record input with the course name ("Kursnamn" in the picture) and make selenium by clicking the download button associated with that course name. Like this:
Is it possible? Hope I made it as clear as possible!
source to share