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?
Users provided relevant link to confirm that, "YES" a full Chrome installation is needed in addition to the actual chromedriver.
Specifically: ChromeDriver uses the same version number scheme as Chrome. See https://www.chromium.org/developers/version-numbers for more details. Each version of ChromeDriver supports Chrome with matching major, minor, and build version numbers.
Selenium cookies can be extensively used for test automation projects for performing cookie-related operations during the process of Selenium automation testing. To realize this requirement, Selenium WebDriver API provides built-in methods for interacting with the cookies.
As Google Chrome dominates the browser market, the use of a ChromeDriver becomes a must. Selenium WebDriver uses the ChromeDriver to communicate test scripts with Google Chrome.
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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With