pythonrobotframeworkselenium2library

chrome options in robot framework


I am trying to download a file from a link on webpage. However I get annoying warning "This type of file can harm...anyway? Keep, Discard". I tried several options to avoid the warning but still getting it. I am using robot framework however I am using python to create new keyword for me.

@keyword('open "${url}" in chrome browser')
    def open_chrome_browser(self, url):
        options = webdriver.ChromeOptions()
        options.add_argument("--start-maximized")
        options.add_argument("--disable-web-security")
        options.add_argument("--allow-running-insecure-content")
        options.add_argument("--safebrowsing-disable-extension-blacklist")
        options.add_argument("--safebrowsing-disable-download-protection")
        prefs = {'safebrowsing.enabled': 'true'}
        options.add_experimental_option("prefs", prefs)
        self.open_browser(url, 'chrome',alias=None, remote_url=False, desired_capabilities=options.to_capabilities(), ff_profile_dir=None)

Can someone please suggest a way to disable the download warning?


Solution

  • I found an answer with some research. For some reason (may be a bug) open_browser does not set capabilities for chrome. So, the alternative is to use 'create_webdriver'. Worked with following code:

    @keyword('open "${url}" in chrome browser')
    def open_chrome_browser(self, url):
        options = webdriver.ChromeOptions()
        options.add_argument("--start-maximized")
        options.add_argument("--disable-web-security")
        options.add_argument("--allow-running-insecure-content")
        options.add_argument("--safebrowsing-disable-extension-blacklist")
        options.add_argument("--safebrowsing-disable-download-protection")
        prefs = {'safebrowsing.enabled': 'true'}
        options.add_experimental_option("prefs", prefs)
        instance = self.create_webdriver('Chrome', desired_capabilities=options.to_capabilities())
        self.go_to(url)