Question
How to make Selenium tests written in Python start Microsoft Edge with a specific browser profile instead of a temporary one?
Answer
By default, Edge WebDriver starts Microsoft Edge with a temporary user data folder. To use an existing profile, pass two command-line arguments through EdgeOptions:
from selenium import webdriver
options = webdriver.EdgeOptions()
options.add_argument(r"user-data-dir=C:\Users\user\AppData\Local\Microsoft\Edge\User Data")
options.add_argument("profile-directory=Profile 1")
driver = webdriver.Edge(options=options)
To find the values for both arguments, open edge://version in Edge and check the Profile path line. For example, for C:\Users\user\AppData\Local\Microsoft\Edge\User Data\Profile 1:
-
user-data-diris everything up to and includingUser Data; -
profile-directoryis the last folder name:Default,Profile 1,Profile 2, and so on. When the profile path ends withDefault, theprofile-directoryargument can be omitted.
Close all running Microsoft Edge instances before starting the tests: while the profile is in use by another Edge process, the WebDriver session fails to start (for example, with InvalidArgumentException). Background Edge processes count as well, so end them in Task Manager if the error persists after closing the browser windows.
More details: Capabilities and EdgeOptions in the Microsoft Edge documentation and How to open a profile using WebDriver in Python Selenium on Microsoft Q&A.
Comments
0 comments
Please sign in to leave a comment.