I am doing tests using whatsapp web, so every time I run selenium, I read the qr code and start the tests, and I have to do this every time, I would like to know if there is a way to save the browser state, save session, some way to start the browser without having to read the qr code again.
I'm using python for this.
I tried this way, but I can not save cookies:
Saving the file:
import pickle
import selenium.webdriver
driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))
Retrieving the file:
import pickle
import selenium.webdriver
driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
driver.add_cookie(cookie)
I use pprint to show the driver.get_cookies () and it returns an empty array, I thought it might be because it takes before loading the cookies, but then I put it in a while while the array was empty it would try and try but still, it just takes the empty array.