python-3.xselenium-webdriverselenium-chromedriver

How to make chromedriver remember my settings for launching an app trough the browser with python selenium?


I am making an app with Selenium and Chromedriver on Python 3.6.3, the app opens a magnet torrent link, but the browser always asks if the user wants to launch BitTorrent("remember my choice" does not work obviously).

I want to make the whole browser invisible with the --headless flag once i'm done coding the app, so the user will not be able to click that if i decided to just leave it as it is. Could someone please tell me how to make it so that chromedriver remembers to allow launching apps through the browser? I've been looking a lot and can't find any solution.


Solution

  • By default, ChromeDriver will create a new temporary profile for each session. In your case, you could use a custom profile (in which your BitTorrent setting is saved).

    In your code tell chromedriver where the profile is located, like this:

    from selenium.webdriver.chrome.options import Options
    ...
    chrome_options = Options()
    chrome_options.add_argument("user-data-dir=/path/to/your/custom/profile");
    ...
    driver = webdriver.Chrome(chrome_options=chrome_options)