Python 如何使用部分链接文本单击链接
我对python和selenium比较陌生。如何使用WebDriverWait使用部分链接文本单击链接。 我有以下用于单击x_路径的工作片段Python 如何使用部分链接文本单击链接,python,html,selenium,web-scraping,automation,Python,Html,Selenium,Web Scraping,Automation,我对python和selenium比较陌生。如何使用WebDriverWait使用部分链接文本单击链接。 我有以下用于单击x_路径的工作片段 from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By WebDriverW
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "#my_xpath"))).click()
您可以使用By.PARTIAL\u LINK\u文本,但请注意,它仅适用于标记
您还可以使用xpath f'/*[contains.,{text}]'在所有标记中按部分文本进行定位
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, f'//*[contains(., "{text}")]'))).click()
By.PARTIAL_LINK_文本仅适用于标记。你为什么要这么做?@Guy是的,我只是用它来点击标签,需要它来点击一个充满链接的页面,我想根据用户输入搜索链接。
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, f'//*[contains(., "{text}")]'))).click()