Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用部分链接文本单击链接_Python_Html_Selenium_Web Scraping_Automation - Fatal编程技术网

Python 如何使用部分链接文本单击链接

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

我对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    
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()