How to open a profile using WebDriver in python selenium?

sonu rajput 25 Reputation points
2023-10-28T12:21:18.5666667+00:00

I want to open a specific profile using webdriver, but I am Geeting errors while opening it.

raise exception_class(message, screen, stacktrace)

InvalidArgumentException: invalid argument
  (Session info: MicrosoftEdge=118.0.2088.69)
Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,160 questions
{count} votes

Accepted answer
  1. Yu Zhou-MSFT 12,371 Reputation points Microsoft Vendor
    2023-10-30T09:43:52.5533333+00:00

    Hi @sonu rajput

    Do you use Edge browser? If yes, you can refer to the following code sample. Please note that change the Edge WebDriver path and Profile path to your owns. Please kill all existing Edge instance before you execute the code:

    from selenium import webdriver
    from selenium.webdriver.edge.service import Service
    from time import sleep
    
    ser = Service("E:\\webdriver\\msedgedriver.exe")
    edge_options = webdriver.EdgeOptions()
    edge_options.use_chromium = True
    edge_options.add_argument("user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\Edge\\User Data")
    edge_options.add_argument("profile-directory=Profile 1")
    
    driver = webdriver.Edge(service = ser,options = edge_options)
    driver.get('https://www.bing.com')
    
    sleep(20)
    

    You can find the profile path in edge://version/:User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Regards,

    Yu Zhou

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. suraj sharma 85 Reputation points
    2023-10-30T04:40:14.2233333+00:00

    It seems like you’re trying to open a specific profile using Selenium WebDriver and encountering an InvalidArgumentException. This error typically occurs when an invalid argument is passed to a method.

    If you’re trying to open a specific browser profile, you might need to specify the correct path to the profile in your WebDriver options. Here’s an example of how you can do this:

    from selenium import webdriver

    from selenium.webdriver.chrome.options import Options

    options = webdriver.ChromeOptions()

    options.add_argument("user-data-dir=C:\path\to\your\profile") # replace with your path

    driver = webdriver.Chrome(executable_path="your_driver_path", options=options) # replace with your driver path

    Please replace "C:\path\to\your\profile" with the actual path to your browser profile and "your_driver_path" with the path to your WebDriver executable.

    Also, ensure that the profile is not in use when you’re running your script, as this can cause issues.

    1 person found this answer helpful.