问题
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