webdirver.add_cockie
时间: 2023-12-17 08:02:08 浏览: 23
()This method is used to add a cookie to the current session. The cookie should be specified as a dictionary with the following keys:
- 'name': The name of the cookie.
- 'value': The value of the cookie.
- 'path': The path on the server where the cookie is valid. If not specified, defaults to '/'.
- 'domain': The domain to which the cookie belongs. If not specified, defaults to the current domain.
- 'secure': Whether the cookie should only be sent over a secure connection (i.e. HTTPS). Defaults to False.
- 'expiry': The expiry date of the cookie. This should be a Unix timestamp in seconds.
Example usage:
```
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.example.com')
cookie = {
'name': 'my_cookie',
'value': '123456',
'path': '/',
'domain': 'example.com',
'secure': False,
'expiry': 1631635200 # Unix timestamp for September 15, 2021
}
driver.add_cookie(cookie)
```