How to use predefined chrome profile in selenium for python?

冷暖自知 提交于 2019-12-23 03:49:11

问题


I have several custom profile in my chrome browser. for example i want to use "test 2" profile to be used in my selenium. (see the picture below)

https://i.stack.imgur.com/iYcG8.png

This is the code i see from the internet.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument(r'user-data-dir=C:\Users\mycomputer\AppData\Local\Google\Chrome\User Data')
browser = webdriver.Chrome(executable_path=r"C:\Users\mycomputer\AppData\Local\Programs\Python\Python36-32\chromedriver.exe", chrome_options=options)

How can i use the "test 2" profile? Thank You.


回答1:


You just need add one more argument:

options.add_argument('--profile-directory=Profile 1')

Profile 1 - is a directory of your profile and its name is not like a profile name. You can explore all the profile direstories in your user-data-dir. How to find out what dir is the dir for "test 2" profile - you can find here https://superuser.com/a/723145



来源:https://stackoverflow.com/questions/47901696/how-to-use-predefined-chrome-profile-in-selenium-for-python

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