admin管理员组

文章数量:1310126

I want to get to a particular session in firefox, so my login data is saved

from selenium import webdriver

profile_path = "/home/XXXX/.mozilla/firefox/XXXX.selenium1"  # particular profile - I hid some part of the path for privacy reason

options = webdriver.FirefoxOptions()
options.add_argument(f"--profile={profile_path}")

driver = webdriver.Firefox(options=options)
driver.get(url)

However, the get seems not to work. Firefox opens but I need to navigate to the page manually.

Instead, if I do not use a profile, i.e.,

from selenium import webdriver


driver = webdriver.Firefox()
driver.get(url)

Firefox opens the right page... but of course, I am not logged in.

I would like to get the first script to work.

I want to get to a particular session in firefox, so my login data is saved

from selenium import webdriver

profile_path = "/home/XXXX/.mozilla/firefox/XXXX.selenium1"  # particular profile - I hid some part of the path for privacy reason

options = webdriver.FirefoxOptions()
options.add_argument(f"--profile={profile_path}")

driver = webdriver.Firefox(options=options)
driver.get(url)

However, the get seems not to work. Firefox opens but I need to navigate to the page manually.

Instead, if I do not use a profile, i.e.,

from selenium import webdriver


driver = webdriver.Firefox()
driver.get(url)

Firefox opens the right page... but of course, I am not logged in.

I would like to get the first script to work.

Share Improve this question edited Feb 3 at 14:13 TylerH 21.1k77 gold badges79 silver badges112 bronze badges asked Feb 2 at 11:02 SamSam 3241 gold badge4 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You can try to export the session's cookies to use them in the future sessions: Start your selenium session, login to your FireFox profile, then:

with open(path, "wb") as file:
        pickle.dump(driver.get_cookies(), file)

In the next sessions load the cookies as follows:

with open(path, "rb") as file:
        cookies = pickle.load(file)
        for cookie in cookies:
            driver.add_cookie(cookie)

本文标签: pythonNavigate Firefox with SeleniumStack Overflow