Loading Default Profile in Chrome with Python Selenium Webdriver
In order to persist cookies and site preferences across sessions in Chrome, it is necessary to launch the browser with its default profile.
Solution:
Utilizing the webdriver.ChromeOptions class, specify the path to the default profile using the add_argument method:
<code class="python">options = webdriver.ChromeOptions() options.add_argument("user-data-dir=C:\Path")</code>
Replace "C:Path" with the actual path to your Chrome profile data. To determine this path, navigate to chrome://version in the address bar. For instance, if your path is displayed as "C:UserspcAppDataLocalGoogleChromeUser DataDefault", only include the path up to "User Data":
<code class="python">options.add_argument("user-data-dir=C:\Users\pc\AppData\Local\Google\Chrome\User Data")</code>
Finally, create a webdriver.Chrome instance with the specified options:
<code class="python">w = webdriver.Chrome(executable_path="C:\Users\chromedriver.exe", chrome_options=options)</code>
The above is the detailed content of How to Load the Default Profile in Chrome with Python Selenium Webdriver?. For more information, please follow other related articles on the PHP Chinese website!