Can I run Selenium ChromeDriver with cookies from actual Chrome installation?
Solution 1
Everytime Selenium opens a browser (Chrome/Firefox/IE) it opens a canonical form of that browser. As a tester, you can set browser preferences using DesiredCapabilities object and for chrome you also can use ChromeOptions object, for passing chrome command line arguments.
To choose your profile
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");
For more on chrome driver capabilities: https://sites.google.com/a/chromium.org/chromedriver/capabilities
For more about user-data-dir command line option for chrome:
https://www.chromium.org/user-experience/user-data-directory
Solution 2
Try this:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)
To find path to your chrome profile data you need to type chrome://version/ into address bar . For ex. mine is displayed as C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default, to use it in the script I had to exclude \Default\ so we end up with only C:\Users\pc\AppData\Local\Google\Chrome\User Data.
Source:How to load default profile in chrome using Python Selenium Webdriver?
Satisfakshin
Updated on July 09, 2022Comments
-
Satisfakshin almost 2 years
So I'm running a selenium test using IntelliJ IDEA + chromedriver on an Ubuntu machine...
In my Google Chrome installation, I have logged in to an account, say Google. When I access http://accounts.google.com in the selenium test, I get to the log in page instead of the actual account management page.
I'm pretty sure that I don't fully understand the exact way that Selenium and the chrome driver operate, but I do remember that having 'Google Chrome installed in the default location' is one of the requirements of running a Selenium test with the chrome driver.
Can I run in the context of my installed browser i.e. have access to my browser history and cookies?
-
Satisfakshin over 8 yearsThanks for the help parishodak! This answers my question.
-
parishodak over 8 yearsglad to be of help @satisfakshin. I am not sure why you need your profile to work. this will affect the test cases running on another user's machine.
-
Satisfakshin over 8 yearsActually just making a proof of concept for something