0

So I want to store a Whatsapp Web session in order to not having to scan Whatsapp Web's QR-Code every time. I did it with the following code:

options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:/Users/Pascal/AppData/Local/Google/Chrome/User Data")
browser = webdriver.Chrome(executable_path="C:/Users/Pascal/Desktop/chromedriver.exe", options = options)
browser.get("https://web.whatsapp.com/")

The above code worked perfectly (Chromebrowser) but the following code which is almost the same does not work:

options = webdriver.FirefoxOptions()
options.add_argument("--user-data-dir=C:/Users/Pascal/AppData/Roaming/Mozilla/Firefox/Profiles/iddwgmst.default-release")
browser = webdriver.Firefox(executable_path="C:/Users/Pascal/Desktop/geckodriver.exe", options = options)
browser.get("https://web.whatsapp.com/")

Why does it not work with firefox? The QR-Code comes up every time but I have loaded the firefox profile to the browser/driver so it seems like firefox does not store whatsapp webs data... But then, if I go into whatsapp web in my normal firefox browser, it stores the data again and I don't have to rescan... I am confused by this problem.

I really want it with firefox to be working cause chromedriver does not support emojis :/

Any Ideas?

Svetlana Levinsohn
  • 1,550
  • 3
  • 10
  • 19
derpascal
  • 172
  • 1
  • 10
  • Firefox differs from Chrome in that they use two locations to store user data. One is in "roaming" and the other in "local". Local is used mainly for temporary files I think... so mayyybe you need that here for an uploaded image file? – pcalkins Oct 16 '20 at 19:25
  • in the firefox profile that is inside roaming, there is a folder called "https+++web.whatsapp.com" and in the local there is not... But it doesnt work if I use that one :/ – derpascal Oct 16 '20 at 20:25
  • it's possible it's pointing to a temporary file... seems kind of odd though. If that were the case, it'd be in local... but that would be a problem because Geckodriver/Firefox will create it's own folder for use as temp and then clean it up after. – pcalkins Oct 16 '20 at 21:48

1 Answers1

0

I solved it. For Firefox it works with:

profile = webdriver.firefox.firefox_profile.FirefoxProfile("C:/Users/Pascal/AppData/Roaming/Mozilla/Firefox/Profiles/iddwgmst.default-release")
        self.browser = webdriver.Firefox(executable_path = os.path.dirname(os.path.realpath(__file__)) + "\\geckodriver.exe" , firefox_profile = profile)
        self.browser.get("https://web.whatsapp.com/")

But for chrome it works with:

options = webdriver.ChromeOptions()
        options.add_argument("--user-data-dir=C:/Users/Pascal/AppData/Local/Google/Chrome/User Data")
        self.browser = webdriver.Chrome(executable_path = os.path.dirname(os.path.realpath(__file__)) + "\\chromedriver.exe", options = options)
        self.browser.get("https://web.whatsapp.com/")

Here, geckodriver and chromedriver are in the same folder as the main.py

derpascal
  • 172
  • 1
  • 10