Saves browser state or cookies using selenium

0

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:

link

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.

    
asked by anonymous 28.09.2017 / 22:59

1 answer

0

Save Wictor,

One solution that comes close to what you need to accomplish in a scalable way would be to use a hack technique called Phishing , I found a project that uses Selenium, Node.js and Sockets.io.

GitHub: Whatsapp Phishing

I tested it and it works, I believe that I can use this project as a basis to solve your question, because it captures the authentication information of the web.whatsapp.

I hope I have helped, [] 's

    
07.12.2017 / 13:13