AttributeError: 'WebDriver' object has no attribute 'sleep'
时间: 2023-09-10 21:04:41 浏览: 52
This error occurs when you try to use the `sleep()` method on a `WebDriver` object, which does not have this attribute. The `sleep()` method is part of the `time` module, so you need to import this module and use the method like this:
```
import time
time.sleep(5) # waits for 5 seconds
```
Alternatively, you can use the `WebDriverWait` class to wait for an element to appear on the page before proceeding:
```
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.ID, 'my_element')))
```
This will wait for up to 10 seconds for the element with ID 'my_element' to appear on the page, and then return the element when it is found.