AttributeError: 'WebDriver' object has no attribute 'find_element_by_id'
时间: 2023-09-21 18:03:07 浏览: 154
webdriver不能启动浏览器,报module ‘selenium.webdriver’ has no attribute”问题解决办法
5星 · 资源好评率100%
This error occurs when you try to use the "find_element_by_id" method on a WebDriver object that has not been instantiated properly.
To fix this error, you need to make sure that you have created a WebDriver instance and that it has been properly initialized. Here's an example of how to initialize a WebDriver object using the ChromeDriver:
```python
from selenium import webdriver
# create a new ChromeDriver instance
driver = webdriver.Chrome()
# navigate to a website
driver.get("https://www.example.com")
# find an element by its ID
element = driver.find_element_by_id("my-id")
```
In this example, we create a new instance of the ChromeDriver and navigate to a website. Then, we use the "find_element_by_id" method to locate an element on the page by its ID.
阅读全文