The solution is: First visit the home page of the website whose cookies you are trying to add.
# first visit home page url = "https://www.website.com" driver.get(url) # add cookies from pickled-txt or a txt file cookies = pickle.load(open("cookies.pkl", "rb")) for cookie in cookies: driver.add_cookie(cookie) # visit again and you shall see your account logged in url = "https://www.website.com" driver.get(url)
The reason is:
- Selenium webdriver init with default url
- add_cookie require current url is under the domain pattern of cookie.
data:will not match any cookie domain
So, you get
invalid cookie domain error.