driver.find_element() xpath
时间: 2024-01-22 20:38:48 浏览: 94
`driver.find_element_by_xpath()` is a method in Selenium that allows you to locate an element on a web page using its XPath expression.
Example:
```python
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/")
search_bar = driver.find_element_by_xpath('//input[@name="q"]')
search_bar.send_keys("Selenium")
search_bar.submit()
driver.quit()
```
In this example, we first navigate to the Google homepage using the Chrome driver. We then locate the search bar on the page using its XPath expression (`//input[@name="q"]`) and store it in the `search_bar` variable. We send the text "Selenium" to the search bar and submit the search. Finally, we close the driver.
阅读全文