I am trying to use python and selenium to automate some tasks in firefox. When I download a file, that pop up comes up asking if you want to open or save, and a check box for do this every time with this kind of file. I have found that check box does not work unless you install the add on Web Page Fixer. I have that installed normally, but when I use python + selenium it uses a profile with no add ons.
The internet has instructed me to create another profile by closing Firefox, opening /Applications/Utilities, then typing the command:
/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
I then create a new profile that I will use with selenium. I set the name and change the folder name. The profile name is "PTI_Auto_Profile". The folder path displays as follows:
/users/User/Library/Application Support/Firefox/Profiles/Selenium/
When I am done. I click 'Start Firefox', and the following error appears on my terminal screen.
2013-04-11 11:57:30.422 firefox-bin[2248:707] invalid drawable
conf-room:~ User$ 2013-04-11 11:58:00.350 firefox-bin[2251:303] invalid drawable
I've tried the following to no success.
profile = webdriver.FirefoxProfile(os.path.expanduser("~/Library/Application Support/Firefox/Profiles/Selenium/"))
driver = webdriver.Firefox(firefox_profile=profile)
No error, default user.
profile = webdriver.FirefoxProfile(os.path.expanduser("~/Library/Application Support/Firefox/Profiles/Selenium/"))
driver = webdriver.Firefox(profile)
No error, default user.
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv/xls")
driver = webdriver.Firefox(firefox_profile=fp)
Error: fp.set_preference("browser.download.dir",getcwd()) NameError: name 'getcwd' is not defined
Any ideas on what I am doing wrong? Thank you!
p.s. I am using mac os x 10.8.2, python 2.7, firefox 20
SOLUTION PROVIDED BY Corey Goldberg. This should work for all excel versions.
import os
from selenium import webdriver
profile = 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', ('application/vnd.ms-excel'))
driver = webdriver.Firefox(profile)
We can open Chrome default profile with Selenium. To get the Chrome profile path, we need to input chrome://version/ in the Chrome browser and then press enter. We need to use the ChromeOptions class to open the default Chrome profile. We need to use the add_argument method to specify the path of the Chrome profile.
We can use a specific Chrome profile in Selenium. This can be done with the help of the ChromeOptions class. We need to create an object of this class and then apply addArguments method on it. The path of the specific Chrome profile that we want to use is passed as a parameter to this method.
Selenium comes with default Mozilla Firefox driver which is bundled in Selenium WebDriver jar file.
Generally to run tests on our local machine, we will just specify as WebDriver driver = new FirefoxDriver(); to run on Firefox browser. System. setProperty("webdriver. gecko.
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 os
from selenium import webdriver
profile = 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:
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 linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources;pkg_resources.get_distribution("selenium").version
jmunsch@NE-522:~/Desktop/work$ firefox --version
Mozilla Firefox 26.0
@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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With