How to make selenium webdriver open in google chrome without Incognito

不想你离开。 提交于 2021-02-07 11:15:00

问题


I'm using selenium for the past 1 month. I want to create some small applications using selenium. Selenium webdriver opens an incognito window when I run it. Is there any way to make it launch in normal window(i.e which has my accounts logged in)?

This is the code which I'm using : (python code in linux)

chromedriver = Path to chrome driver
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get("http://www.gmail.com")

回答1:


If you want to re-use your login/authentication cookies, you can save the cookies and then load it again.

You can refer to this post:

To save cookies:

import pickle
import selenium.webdriver 

driver = selenium.webdriver.Firefox()
driver.get("http://www.google.com")
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))

To add back the cookies:

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)

If you want to load an extension when Chrome starts, you can refer to this post and this post.



来源:https://stackoverflow.com/questions/24754760/how-to-make-selenium-webdriver-open-in-google-chrome-without-incognito

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!