This question suggests how to change the default download directory in a firefox profile that is to be later used by selenium. In my case I must download .pdf files by default to a certain directory. The problem is that using a new profile with every instance of a web driver prompts the download dialog box (no downloads are made by default).
Using the default profile garbles the current session with the existing one (if present).
ProfilesIni profile = new ProfilesIni();
// The default profile that is used "outside" of selenium
FirefoxProfile firefoxProfile = profile.getProfile("default");
WebDriver webDriver = new FirefoxDriver(firefoxProfile);
In the default profile, the pdf files are downloaded as required without prompting for a download dialog.
How can I customize the profile the web driver uses so that pdf files are downloaded in selenium as well (without requiring confirmation on behalf of the user)?
Browser settings can be set as preferences within the web driver as follows:
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv, application/csv, text/comma-separated-values");
WebDriver webDriver = new FirefoxDriver(firefoxProfile);
Simply add the MIME type of the file to the above preference list.
Related
I am able to see the addon (browsec VPN) icon on FF while running my java script in selenium webdriver but the VPN addon is always disable on FF instance - I have used the following code to access addon;
WebDriver driver = null;
FirefoxProfile profile = new FirefoxProfile();
File addonpath = new File("addonpath");
profile.addExtension(addonpath);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability("browsec", true);
driver = new FirefoxDriver(profile);
driver.get("application url");
Thread.sleep(3000);
driver.quit();
I can see the browsec VPN icon executing above code but It is in disable form, my question is how can I get it enabled using selenium webdriver. Thank you
You'd need to enable it using 'setPreference' I use firebug in some of my tests and along with specifying the addon path it needs the following:
profile.setPreference("extensions.firebug.onByDefault", true);
It may not be exactly the same preference name for your addon but there should be something similar you can find if you type "about:config" in the address bar when you have the addon installed and search for "extensions." in there and find your addon. Just add this in before you initialise the driver and it should work.
1) My Firefox is installed on following path C:\Program Files\Mozilla Firefox\firefox.exe 2) I'm using Windows 7 64 bit version. 3) I'm using Firefox 46.0 version. 4) I'm using selenium-java-2.53.0 version. 5) Firefox profile is located on C:\Users\xxxxxx\automation
I created separate profile and tried to use same in code but still web driver is creating in anonymous temporary profile only. Please help me on this issue.
I have done these ways.
First Method
ProfilesIni profile = new ProfilesIni(); FirefoxProfile myprofile = profile.getProfile("automation");
DesiredCapabilities capability = DesiredCapabilities.firefox(); capability.setCapability(FirefoxDriver.PROFILE, myprofile);
driver = new FirefoxDriver(capability);
Second method
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("automation");
driver = new FirefoxDriver(myprofile);
Third Method
FirefoxProfile myprofile =profile.getProfile("C:\\Users\\xxxx\\NewProfile");driver = new FirefoxDriver(myprofile);
Fourth Method
FirefoxProfile myprofile=new FirefoxProfile(new File("C:\\Users\\xxxxx\\NewProfile"));driver = new FirefoxDriver(myprofile);
Note: When I'm executing following command 'C:\Program Files\Mozilla Firefox\firefox.exe" -p' its showing 2 profile is available first is default and another one is I created for Automation in the name of automation and able to launch manually without any issues.
But when automation runs i executed "about:support" in firefox address bar and reviewed the profile folder its showing anonymous temporary profile only.
i have many profiles in Firefox to open in selenium, now i want to open a Firefox profile in Private Browsing Mode. How to Open Firefox Profile with privatebrowsing in Selenium? here is my code
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("1");
ffprofile.set_preference("browser.privatebrowsing.autostart", True);
WebDriver driver = new FirefoxDriver(ffprofile);
driver.get("http://proxy.cm/");
try {Thread.sleep(13000);} catch (InterruptedException e) {e.printStackTrace();}
this line shows error
ffprofile.set_preference("browser.privatebrowsing.autostart", True);
above line show error "True cannot be resolved to a variable".
One more problem i am facing that Selenium is not updating Firefox
profiles, i mean i installed some new extention, i also changed some
setting in firefox profile but Selenium always open Firefox with old settings, extensions.
how can i force Selenium to open firefox profile with updated new settings and extentions?
Your syntax is not Java, but Python (I think).
ffprofile.setPreference("browser.privatebrowsing.autostart", true);
Note the difference in setPreference and true.
And for the second problem you can specify the path to the version you want
FirefoxBinary binary = new FirefoxBinary(new File("path_to_firefox"));
FirefoxProfile ffprofile = profile.getProfile("1");
ffprofile.setPreference("browser.privatebrowsing.autostart", true);
WebDriver driver = new FirefoxDriver(binary, ffprofile);
Another option is to define the path for Firefox in System property
System.setProperty("webdriver.firefox.bin", "/Applications/Firefox-2.app/Contents/MacOS/firefox-bin");
I have created Firefox profile for webDriver.
Code is below for the created profile:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myProfile = profile.getProfile("Selenium");
driver = new FirefoxDriver(myProfile);
Where "Selenium" is profile name. It is working fine in my machine.
Now, I want to deploy this project to some one else. But he has not set the preferences in firefox profile as same as mine. So, he cant use the script.
How can i add this firefox profile in my framework/project, so if i give the same framework to some else, he can use the same functionality.
You need to backup your profile as described in this tutorial from Mozilla. Than make that profile part of you project (so drop it somewhere into src/test/resources) and just do
File profileDir = new File(profileLocation);
FirefoxProfile profile = new FirefoxProfile(profileDir);
WebDriver driver = new FirefoxDriver(profile);
Or alternatively you can create your own inside Java code, it depends how much settings your profile has.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
WebDriver driver = new FirefoxDriver(profile);
How can I use Selenium with Java with a custom Firefox Profile?
Here is my configuration:
Firefox version: 12
Selenium version: 2.25
Language: Java
Platform: MacOS
Open Terminal
type: /Applications/Firefox.app/Contents/MacOS/firefox-bin -p ( change the path as necessary )
Create a new profile, save it in a directory as you wish..
Start firefox with this profile, add any add-ons, modifications as you wish.
In Selenium, use:
FirefoxBinary binary = new FirefoxBinary();
File firefoxProfileFolder = new File("/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile");
FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
profile.setAcceptUntrustedCertificates(true);
webDriver = new FirefoxDriver(binary, profile);
Again here change the absolute path as required.
Add add-ons like autoAuth to pass the HTML Authorization windows in Firefox to this profile..
For Windows, to create a new Firefox Profile, type:
firefox -profilemanager
in Run that will open the Firefox Profile Manager.
Let's say you have created a profile called Selenium, then you can use the following code:
ProfilesIni listProfiles = new ProfilesIni();
FirefoxProfile profile = listProfiles.getProfile("Selenium");
WebDriver driver = new FirefoxDriver(profile);
You cannot pass HTML authorization window with Selenium.
You have to use Auto IT for this purpose.
AutoIT gives you the platform to manage the windows based components.
You can invoke AUTO IT scripts from Selenium WebDriver