[英]How to do find aria-label using selenium and python
This is my code-->这是我的代码-->
element = driver.find_elements_by_css_selector("[aria-label='收回讚']")
It doesn't work, it creates an None
type.它不起作用,它创建了一个
None
类型。 Any help is appreciated!任何帮助表示赞赏! Thanks in advance!
提前致谢!
update:更新:
my update code:我的更新代码:
try:
element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, "//*[aria-label='收回讚']")))
#check if unlike path exisit
except:
element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.XPATH, "//*[aria-label='讚']")))
element.click()
#if not find like path and click it
To find the element you need to induce WebDriverWait for the visibility_of_element_located()
and you can use either of the following Locator Strategies :要找到您需要为
visibility_of_element_located()
诱导WebDriverWait的元素,您可以使用以下任一Locator Strategies :
Using CSS_SELECTOR
:使用
CSS_SELECTOR
:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[aria-label='收回讚']")))
Using XPATH
:使用
XPATH
:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*[@aria-label='收回讚']")))
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 detailed descroptions in:您可以在以下位置找到一些相关的详细说明:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.