Saves browser status or cookies using Selenium

Asked

Viewed 1,177 times

0

I’m doing tests using the web Whatsapp, so every time I run Selenium, read the qr code and start the tests, and I have to do this every time, I’d like to know if there’s a way to save the state of the browser, save the session, some way to start the browser without the need to read the qr code again.

I’m using python for this.

I tried this way, but I can’t save the cookies:

https://stackoverflow.com/questions/15058462/how-to-save-and-load-cookies-using-python-selenium-webdriver

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"))

Recovering 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 picks up before loading cookies,.

2 answers

1

import os
from selenium import webdriver

dir_path = os.getcwd()
profile = os.path.join(dir_path, "profile", "wpp")
options = webdriver.ChromeOptions()
options.add_argument(
    r"user-data-dir={}".format(profile))

browser = webdriver.Chrome("./chromedriver.exe", chrome_options=options)

browser.get("https://web.whatsapp.com")

was with this problem msm and solved this way. You only need to log in once, dps it enters without needing to scan the QR Code dnv

0

Salve Wictor,

A solution that approaches what you need to accomplish and 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 and it works, I believe I can use this project as a basis to solve your issue, as it captures the web authentication information..

I hope I helped, []’s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.