find_element_by_css_selector
时间: 2023-09-03 19:06:53 浏览: 145
xm.py.tar.gz_python_python 自动测试_python 表单
find_element_by_css_selector is a method used in Selenium WebDriver to locate and return a web element on a webpage using a CSS selector.
The method takes a CSS selector as a parameter and returns the first web element that matches the selector. If no matching element is found, it raises a NoSuchElementException.
Example usage:
```python
from selenium import webdriver
# Create a new instance of the Firefox driver
driver = webdriver.Firefox()
# Navigate to a webpage
driver.get("https://www.example.com")
# Find an element using a CSS selector
element = driver.find_element_by_css_selector("#main-content")
# Do something with the element, like click it or get its text
element.click()
print(element.text)
# Close the browser
driver.quit()
```
阅读全文