How to open specified profile Firefox with Selenium 2 Webdriver? - java

When I use default profile starts without problem. But when i starts with custom profile, firefox starts but stays "blocked". The process remains active consuming 31MB of RAM, but never start. Only start if I killed the process, then starts and works fine with selenium.
I use Windows 7, Firefox 25.0.1 and selenium-server-standalone-2.38.0.jar ¿Maybe problems with compatibility of versions?
This is the code to open the profile:
FirefoxProfile profile = new FirefoxProfile(new File("C:/Users/UserTest/AppData/Roaming/Mozilla/Firefox/Profiles/tydtn9km.testprofile"));
WebDriver driver = new FirefoxDriver(profile);
Edit:
This is my actual code
package org.openqa.selenium.example;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Main {
public static void main(String[] args) {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("Other");
WebDriver driver = new FirefoxDriver(ffprofile);
driver.get("http://google.com");
}
}
Edit 2: Resolved
The problem ocurred because my Firefox profile is located in another partition, and Firefox in the other partition.

I have been using it like this:
First, create a Firefox profile and name it somehow you know. E.g. SELENIUM
Then initialize your profile:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);

Related

Selenium Launches Firefox While Silently Ignoring Profile Preference

There are currently two recommended ways to launch the latest version of Selenium using a specific profile. One is through the Desired Capabilities object and the other us by using Firefox Options.
Desired Capabilities:
public static WebDriver launchFirefoxProfileByFFCapabilities()
{
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "PATH");
ProfilesIni profile = new ProfilesIni();
String profileName = "Profile_1";
FirefoxProfile firefoxProfileByProfilesIni = profile.getProfile(profileName);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, firefoxProfileByProfilesIni);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
driver = new FirefoxDriver(opt);
return driver;
}
Firefox Options:
public static WebDriver launchFirefoxProfileByFFOptions()
{
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "PATH");
ProfilesIni profile = new ProfilesIni();
String profileName = "Profile_1";
FirefoxProfile firefoxProfileByProfilesIni = profile.getProfile(profileName);
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(firefoxProfileByProfilesIni);
driver = new FirefoxDriver(opt);
return driver;
}
I noticed a few interesting discrepancies between the two approaches and I'm trying to understand what is the reason for these discrepancies and how to prevent them.
1) With Firefox Options when the specified Profile Name does not exist (as it appears in the Firefox - Choose User Profile dialog) throws WebDriverException: Unexpected value for profile: null. However with Desired Capabilities no such exception is thrown and Selenium silently ignores the profile preference (which is not ideal)
2) If the Profile Name exists (as it appears in the Firefox - Choose User Profile dialog) but the path in profiles.ini file is incorrect even Firefox Options will launch silently ignore the profile preference and launch WebDriver not connected to any profile
What is the cause of these discrepancies? How can they be prevented?
Thanks
It seems that Capabilities and FirefoxProfile/FirefoxOptions handle the profileIni in a different way.
Could you please modify and add the stack-traces so we can further help you?

Loading Firefox profiles on Selenium causes Firefox to start a minute late. How do I eliminate this delay?

The task I'm required to complete requires me to use Firefox profiles. However, if I use profiles, it takes around 50 seconds for Firefox to startup. Without profiles it takes literally no delay.
I'm looking to eliminate this delay completely since the program itself takes only 25 seconds to run. Any suggestions? My OS is MacOS 10.13.3.
I've included the code for the constructor below.
public test() {
System.setProperty("webdriver.gecko.driver", geckodriver_path);
System.setProperty("webdriver.firefox.bin", firefox_path);
ProfilesIni profile = new ProfilesIni();
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile myprofile = profile.getProfile("test2");
options.setProfile(myprofile);
webDriver = new FirefoxDriver(options);
webDriver.manage().window().maximize();
}

Get profile of firefox ProfilesIni not selecting given profiles when profile count more than 3 including default

Below code didn't changed FF profile when I am having 3(randomly created nos.) custom FF profiles and 1 default.
WebDriver driver;
String profilepath = "<user Dir>/Local/Mozilla/Firefox/Profiles/";
ProfilesIni profilesini = new ProfilesIni();
FirefoxProfile firefoxprofile = new FirefoxProfile(new File(profilepath));
firefoxprofile = profilesini.getProfile("profile_1");
driver = new FirefoxDriver(firefoxprofile);
FF profiles are : profile_1, profile_2 and profile_3. When I run the code FF launched with either 'profile_2 or default'. Not with passed profile name (profile_1)
Am using selenium-sever standalone 2.53.0 and FF 46.0 on Win 10, 64 bit.
If you want to launch a custom firefox profile. This is how you do it.
First you create an object of ProfilesIni then you get the desired firefox profile using getProfile() and then that particular profile is passed to WebDriver initialization.
ProfilesIni profiles = new ProfilesIni();
FirefoxProfile profile = profiles.getProfile("profile_1");
WebDriver driver = new FirefoxDriver(profile);
Hope it helps!

What Firefox Driver does Selenium use?

I’m trying to use Selenium WebDriver with Eclipse and JUnit and a Firefox browser to do a series of Link tests. The trouble I’m having is the Firefox browser is opening some links in a new Window. Note: these are not Alerts.
I have the browser set to open all links in the same window, and if I navigate to the chosen links manually it does what it’s supposed to do. These are the settings of the default browser at present.
browser.link.open_newwindow; 1
browser.link.open_newwindow.disabled_in_fullscreen; true
browser.link.open_newwindow.override.external: 1
browser.link.open_newwindow.restriction; 2
When I run the same thing in Eclipse as a JUnit test from Eclipse the link opens up in a new window!
I commented out driver.close() and checked the browser that Eclipse was using and all the settings are different. There is even another setting that isn’t in my browser.
browser.link.open_newwindow; 2
browser.link.open_newwindow.disabled_in_fullscreen; false
browser.link.open_newwindow.override.external: -1
browser.link.open_newwindow.restriction; 2
browser.link.open_external 2
If I use a profile or force it to use the default profile it the browser it uses has these settings.
browser.link.open_newwindow; 2
browser.link.open_newwindow.disabled_in_fullscreen; true
browser.link.open_newwindow.override.external: 1
browser.link.open_newwindow.restriction; 2
browser.link.open_external 2
From reading previous posts I was of the understanding that Eclipse/Selenium/JUnit would use the default browser installed on my PC. Or at least the default browser profile
My Code:
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Pro2 {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("default");
driver = new FirefoxDriver(ffprofile);
// driver = new FirefoxDriver();
baseUrl = "https://www.google.ie/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
My questions are:
Is it using a different driver(or driver profile)?
If so how do I set the config settings so that all links open in the current window?
You can modify firefox profile before you use it in your tests by calling SetPreference method of the FirefoxProfile class:
ffprofile.SetPreference("browser.link.open_newwindow", "1");

How to Disable JavaScript in WebDriver when automating in Selenium?

I am currently trying to write a test that tests the non-JS version of my website. I use Selenium with Java. I have tried this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", false);
driver = new FirefoxDriver(profile);
driver.get();
However this isn't working. It just loads the page with JavaScript Enabled.
As a workaround I did, this, for the requirement.
It will manually set the javascript.enabled property to false by the following script.
WebDriver driver = new FirefoxDriver();
driver.get("about:config");
Actions act = new Actions(driver);
act.sendKeys(Keys.RETURN).sendKeys("javascript.enabled").perform();
act.sendKeys(Keys.TAB).sendKeys(Keys.RETURN).perform();

Categories