find_elements_by_link_text
时间: 2023-09-02 16:15:44 浏览: 87
find_elements_by_link_text is a method in Selenium WebDriver that searches for all the web elements that have the given link text. It returns a list of web elements that match the search criteria. This method is useful when we want to find all the links on a page that have a specific text. Here is the syntax for using this method:
```
driver.find_elements_by_link_text(link_text)
```
where `link_text` is the text that we want to search for in the links.
For example, if we want to find all the links on a page that have the text "About Us", we can use the following code:
```
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.example.com")
links = driver.find_elements_by_link_text("About Us")
for link in links:
print(link.get_attribute("href"))
```
This code will print the URLs of all the links that have the text "About Us".
阅读全文