Search code examples
pythonselenium-webdriverautomationwebdriver

Python Webdriver : Profile Creation Using Code


is there any way we can create browser profiles using code? chrome,gecko , brave , edge or any other. want to create profiles using code to save time. i tried looking over internet but couldn't find any solution , thanks

i tried looking over github and stackoverflow but no luck. tried chatgpt too


Solution

  • You can create chrome profiles using the code below, just specify the path you want profiles save in & the name of profile :

    import selenium.webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    from selenium.webdriver.chrome.options import Options
    import os
    
    chrome_options = selenium.webdriver.ChromeOptions()
    chrome_options.add_argument('start-maximized')
    chrome_options.add_argument("user-data-dir="+os.path.abspath('Profiles/Jason')) # Put were you want save created profiles
    chrome_options.add_argument("--disable-plugins")
    chrome_options.add_argument("--disable-extensions-file-access-check")
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    driver = selenium.webdriver.Chrome(chrome_options=chrome_options)   
    # Your code here