[英]Python/Selenium Click on an element in a ul
I am new to Python/Selenium (< 3 days).我是 Python/Selenium 的新手(< 3 天)。 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.
我尝试过 find_element_by_link_text、find_element_by_css_selector,但找不到它。
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:根据 HTML,很明显所需字段位于
<iframe>
因此您必须:
Induce WebDriverWait for the desired frame to be available and switch to it . Induce WebDriverWait等待所需的框架可用并切换到它。
Induce WebDriverWait for the desired element to be clickable . Induce WebDriverWait使所需元素可点击。
You can use either of the following Locator Strategies :您可以使用以下任一定位器策略:
Using CSS_SELECTOR
:使用
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
:使用
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:您可以在以下位置找到一些相关讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.