How to use Firefox Profile preferences in Selenium Webdriver


happy_developer_jxnyk9

There are many advantages by using FirefoxProfile preferences in selenium. You have to update the preferences within Firefox. We can do this by instantiating a Firefox Profile object and then update the settings.We will then need to pass this object into FirefoxDriver which will load the profile with your defined settings.

1. How to setup the startup page in Firefox browser

FirefoxProfile profile= new FirefoxProfile();

profile.setPreference(“browser.startup.homepage”,”https://seleniumbycharan.wordpress.com”);

WebDriver driver = new FirefoxDriver(profile);

2. How to set language in profile ?

FirefoxProfile profile= new FirefoxProfile();

profile.setPreference( “intl.accept_languages”, “no,en-us,en” );

WebDriver driver = new FirefoxDriver(profile);

3. How to Change the user agent ?

FirefoxProfile profile = new FirefoxProfile();
profile
.setPreference(“general.useragent.override”, “Any UserAgent String”);
WebDriver driver = new FirefoxDriver(profile);

4. How to Download the files using firefox profile ?

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference(“browser.download.folderList”,2);  profile.setPreference(“browser.download.manager.showWhenStarting”, false); profile.setPreference(“browser.download.dir”, downloadPath); profile.setPreference(“browser.helperApps.neverAsk.openFile”,”application/excel”);

profile.setPreference(“browser.helperApps.neverAsk.saveToDisk”,”application/excel”);

profile.setPreference(“browser.helperApps.alwaysAsk.force”, false);

profile.setPreference(“browser.download.manager.showAlertOnComplete”, false); profile.setPreference(“browser.download.manager.closeWhenDone”, false);

5. How to handle SSL certificate error (Firefox browser) ?

 FirefoxProfile profile = allProfiles.getProfile("CertificateIssue");
profile.setAcceptUntrustedCertificates(true);
profile.setAssumeUntrustedCertificateIssuer(false);
 WebDriver driver = new FirefoxDriver(profile);
driver.get("https://seleniumbycharan.wordpress.com");

I hope this helps you  a lot…!

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s