find_elements_by_link_text
时间: 2023-09-02 12:15:41 浏览: 35
find_elements_by_link_text is a method in Selenium WebDriver that is used to find all the web elements in a page that match the given link text. This method returns a list of all the matching web elements. The syntax of this method is:
driver.find_elements_by_link_text(link_text)
where driver is the instance of the WebDriver, and link_text is the text of the link to be searched.
For example, if we want to find all the web elements with link text 'Sign In' in a page, we can use the following code:
```
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.example.com')
sign_in_links = driver.find_elements_by_link_text('Sign In')
print(len(sign_in_links)) # prints the number of web elements with link text 'Sign In'
```
This code will open the website 'https://www.example.com' in a Chrome browser and find all the web elements with link text 'Sign In'. The number of such elements is printed on the console.