0

I am trying to write a python code that opens a particular website and checks for a value particular variable

This image shows a part of a registeration website  at far right of the image is the status (variable) I want to check

How can I get the value of this variable to check whether the section is closed or opened it returns false if closed and true if opened

this is my code so far (it is missing some parts I hope to get help on these parts)

FireFoxDriverPath = '/Users/User/Desktop/geckodriver-v0.30.0-win64/geckodriver.exe'

url = "https://www.google.com/"

browser = webdriver.Firefox(executable_path=FireFoxDriverPath)

browser.get(url)

element_dropdown =browser.find_element_by_id('course_term_code')
select = Select(element_dropdown)
element_dropdown2=browser.find_element_by_id('course_dept_code')
select2 = Select(element_dropdown2)
try:

    select.select_by_visible_text("Term 221")
    select2.select_by_visible_text("Mathematics")
    browser.refresh()
except NoSuchElemnentException:
    print('The item does not exist')

Note: The drop-downs is to choose semester and course

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
SWE
  • 9
  • 1
    Please share HTML of that page or if possible a link. We can not see web element attributes based on the screen shot picture – Prophet Mar 27 '22 at 12:42
  • Also if you want people to help you here start accepting given you answers – Prophet Mar 27 '22 at 12:42
  • the url (https://registrar.kfupm.edu.sa/courses-classes/course-offering/) I dont how to start accepting giving me answer? – SWE Mar 27 '22 at 13:02
  • This site can’t be reached ERR_CONNECTION_TIMED_OUT – Prophet Mar 27 '22 at 13:05
  • OH I think you need a VPN but I don't how to get one to my location, if you have any other way to provide you the with webpage I will be glad to help – SWE Mar 27 '22 at 13:27
  • you can find the HTML file in this drive like and you can download it and run it on chrome browser https://drive.google.com/file/d/1JfsrtDVXfjp9mQFZhaPuFAYrlX98gNKe/view?usp=sharing – SWE Mar 27 '22 at 13:38

1 Answers1

1

Within the website to select the <option> elements with text as Term 221 and Mathematics and check the Status of Financial Mathematics you need to induce WebDriverWait and you can use either of the following locator strategies:

driver.get('https://registrar.kfupm.edu.sa/courses-classes/course-offering/')
Select(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "select#course_term_code")))).select_by_visible_text("Term 221")
Select(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "select#course_dept_code")))).select_by_visible_text("Mathematics")
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//td[contains(., 'Financial Mathematics')]//following::td/span"))).text)

Console Output:

Open

Note : You have to add the following imports :

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

References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thank you very much for the code it is working totally fine. I just want to know how to get the last two statuses shown in the picture I want it to print (closed closed ) in the same order – SWE Mar 28 '22 at 06:08
  • Please don't copy/paste the code/answers. Try to understand the logic. I have given one example of `Open`. You can create for `Closed`. – undetected Selenium Mar 28 '22 at 06:33