I am new to Python/Selenium (< 3 days). I am trying to click on the "grades" item of an unordered list (Please see image). I have tried find_element_by_link_text, find_element_by_css_selector but am unable to find it.
Image from inspect element
Thanks.
As per the HTML it is pretty clear that the desired field is within an <iframe>
so you have to:
Induce WebDriverWait for the desired frame to be available and switch to it .
Induce WebDriverWait for the desired element to be clickable .
You can use either of the following Locator Strategies :
Using CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"frameDetail"))) element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#grades")))
Using XPATH
:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"frameDetail"))) element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='grades']")))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
You can find a couple of relevant discussions in:
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.