简体   繁体   中英

User profile on Edge using selenium python

Everytime I open edge using selenium, it opens with a new profile. How to set my own profile?

You can use the code below to open Edge with specific profile:

from msedge.selenium_tools import Edge, EdgeOptions

edge_options = EdgeOptions()
edge_options.use_chromium = True    

#Here you set the path of the profile ending with User Data not the profile folder
edge_options.add_argument("user-data-dir=C:\\Users\\username\\AppData\\Local\\Microsoft\\Edge\\User Data"); 

#Here you specify the actual profile folder    
edge_options.add_argument("profile-directory=Profile 1");

edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
driver = Edge(options = edge_options, executable_path = "your\\path\\to\\edge\\webdriver\\msedgedriver.exe")
driver.get('https://google.com')
driver.quit()

The above code uses MS Edge Selenium tools . You need to run the command below to install it:

pip install msedge-selenium-tools selenium==3.141

Please note to change all the paths in the code to your owns. If you don't know the path of the specific profile, you could check edge://version/ like below:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM