AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'
时间: 2023-09-15 17:22:59 浏览: 202
This error occurs when trying to use the method `find_element_by_id()` on a `WebDriver` object that does not have this method.
To resolve this error, make sure that you have imported the necessary modules and that you have initialized the `WebDriver` object correctly. Additionally, ensure that the element you are trying to locate exists on the web page and that you are using the correct ID value.
Here is an example of how to use `find_element_by_id()` correctly:
```python
from selenium import webdriver
# initialize the webdriver object
driver = webdriver.Chrome()
# navigate to a web page
driver.get("https://www.example.com")
# locate an element by its ID value
element = driver.find_element_by_id("my-id")
```
阅读全文