Setting selenium to use custom profile, but it keeps opening with default Setting selenium to use custom profile, but it keeps opening with default python python

Setting selenium to use custom profile, but it keeps opening with default


Error: fp.set_preference("browser.download.dir",getcwd()) NameError: name 'getcwd' is not defined

getcwd() is not defined. So I assume you want the getcwd from the os module:

add: import os , and then invoke with os.getcwd().

or you could just add the import for this function:from os import getcwd

your example with the proper imports included:

import osfrom selenium import webdriverprofile = webdriver.FirefoxProfile()profile.set_preference('browser.download.folderList', 2)profile.set_preference('browser.download.manager.showWhenStarting', False)profile.set_preference('browser.download.dir', os.getcwd())profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv/xls')driver = webdriver.Firefox(profile)


I did the following:

Open Profile Directory

Or:

Linux: ls -d /home/$USER/.mozilla/firefox/*.default/ to see user profile directories

Mac: ls -d ~/Library/Application\ Support/Firefox/Profiles/*

Output:

/home/jmunsch/.mozilla/firefox/xfoyzfsb.default//home/jmunsch/.mozilla/firefox/yxjwk1py.default/

To load a custom user profile I ran through creating a profile in firefox and then did the following with the python selenium webdriver code:

def setUp(self):    self.profile = webdriver.FirefoxProfile('/home/jmunsch/.mozilla/firefox/yxjwk1py.default')    self.driver = webdriver.Firefox(self.profile)

System Info:

Python 2.7.3 (default, Sep 26 2013, 20:08:41) [GCC 4.6.3] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import pkg_resources;pkg_resources.get_distribution("selenium").versionjmunsch@NE-522:~/Desktop/work$ firefox --versionMozilla Firefox 26.0

also note

@Corey's answer to manually set a profile

All of the configurables can be found under about:config:

profile.set_preference('browser.download.folderList', 2)


You should add this:

profile.set_preference("browser.helperApps.neverAsk.openFile",    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml")

It does work!