Chromedriver, Selenium - Automate downloads

前端 未结 1 490
失恋的感觉
失恋的感觉 2020-11-28 13:28

I am using Selenium 2.43.0 with Python 2.7.5. At one point, the test clicks on a button which sends form information to the server. If the request is successful, the serve

相关标签:
1条回答
  • 2020-11-28 13:47

    I had to dig into the source code on this one - I couldn't find any docs listing the full set of Chrome User Preferences.

    The key is "plugins.plugins_disabled": ["Chrome PDF Viewer"]}

    FULL CODE:

    dc = DesiredCapabilities.CHROME
    dc['loggingPrefs'] = {'browser': 'ALL'}
    
    chrome_profile = webdriver.ChromeOptions()
    profile = {"download.default_directory": "C:\\SeleniumTests\\PDF",
               "download.prompt_for_download": False,
               "download.directory_upgrade": True,
               "plugins.plugins_disabled": ["Chrome PDF Viewer"]}
    chrome_profile.add_experimental_option("prefs", profile)
    
    #Helpful command line switches
    # http://peter.sh/experiments/chromium-command-line-switches/
    chrome_profile.add_argument("--disable-extensions")
    
    self.driver = webdriver.Chrome(executable_path="C:\\SeleniumTests\\chromedriver.exe",
                                   chrome_options=chrome_profile,
                                   service_args=["--log-path=C:\\SeleniumTests\\chromedriver.log"],
                                   desired_capabilities=dc)
    

    Interestingly the blanket command chrome_profile.add_argument("--disable-plugins") switch did not solve this problem. But I prefer the more surgical approach anyways.

    0 讨论(0)
提交回复
热议问题