0

i usually use the following function to set profile for Firefox

def FirefoxProfile(path, handlers):
        debug = True
        if debug: print "%r - %s(%r, %r)" % (time.asctime(), "FirefoxProfile", path, handlers)
        profile = webdriver.FirefoxProfile()
        profile.set_preference("browser.download.manager.showWhenStarting",False)
        if (not(isfile(path)) & exists(path)):
            profile.set_preference("browser.download.folderList",2)
            profile.set_preference("browser.download.dir", path)
            profile.set_preference("browser.download.downloadDir", path)
            profile.set_preference("browser.download.defaultFolder", path)
        else:
            profile.set_preference("browser.download.folderList",1)
        profile.set_preference("browser.helperApps.alwaysAsk.force", False)
        profile.set_preference("browser.helperApps.neverAsk.saveToDisk", handlers)
        profile.set_preference("pdfjs.disabled", True)
        profile.update_preferences()

        if debug: print "done. - %r" % time.asctime()
        return profile

# Somewhere else 
self.profile = PyWebBot.FirefoxProfile(config['downloads'], config['handlers'])
self.driver = webdriver.Firefox(self.profile)

how to do this for Chrome ? i need the same settings

  1. Save file to custom directory
  2. Autosave (never ask)

Edit

def Google_desired_capabilities(path=os.getcwd()):
        return {"prefs": {
                            "download.default_directory": path,
                            "download.prompt_for_download": False
                        },
                "switches": ["-silent", "--disable-logging"],
                "chromeOptions": {
                            "args": ["-silent", "--disable-logging"]
                        }
                }

Update

    chrome_options = webdriver.ChromeOptions()
    chrome_options.prefs = PyWebBot.Google_desired_capabilities(config['downloads'])['prefs']
    self.driver = webdriver.Chrome(path.join(config['drivers'],'chromedriver.exe'), chrome_options=chrome_options)
Ben Ishak
  • 669
  • 3
  • 11
  • 27
  • 1
    The idea is to set `chrome.prefs`, however, this is somehow binding dependent, not sure about Python. [Here](http://stackoverflow.com/q/15824996/1177636) is .NET. – Yi Zeng Jan 13 '14 at 03:46
  • yeah i thought ChromeOption just create a dictionaray when add arguments but i did that too but it didnt work, check update! – Ben Ishak Jan 14 '14 at 23:15

0 Answers0