So I downloaded the new version of selenium (3.6.0)and been having issues getting the profiles for firefox to work. Originally I had it working with 3.5.3, but I am at a loss now.. I have tried everything I can think of and on these forums with no avail!
I am trying to load a user profile "Selenium" - I have tried
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("SELENIUM");
WebDriver driver = new FirefoxDriver(ffprofile);
and this
ProfilesIni profile = new ProfilesIni();
FirefoxProfile profile = listProfiles.getProfile("Selenium");
WebDriver driver = new FirefoxDriver(profile);
I've also tried setting the Firefox profile to be default, so that it just opens that one, but I now see that selenium creates an anonymous profile each instance.
This was working before, but I see it is now depreciated. and I cannot figure out how to use FirefoxOptions to open the the profile. If you could point me in the right direction that be great! I've tried the java example from the release updates but it does not work correctly..
I have searched every link on google, for many things related, and simply cannot find an approach that will work. Everything keeps pointing me back to that the way I am doing it now is depreciated..
Thanks
As you are using latest version of selenium,I would suggest you to use DesiredCapabilities in org.openqu.selenium.remote package and your jdk compliance level should be 1.8.
System.setProperty("webdriver.gecko.driver","path_to_geckodriver.exe");
File file = new File(path_to_your_firefox_profile);
DesiredCapabilities dc = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile(file);
dc.setCapability(FirefoxDriver.PROFILE, profile);
FirefoxDriver driver = new FirefoxDriver(dc);
driver.get("https://www.google.com");
Refer this blog for more details.
http://himanshuupadhyay.blogspot.com/2014/01/firefox-webdriver-profile-desired.html
Let me know this works out for you.
All answers totally ignore the "setProfile" question.
Here's the answer, how to implement "setProfile":
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile myProfile = allProfiles.getProfile("Selenium");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(myProfile);
WebDriver driver = new FirefoxDriver(firefoxOptions);
The probable reason for this is the changelog for 3.6.0 stating -
All Option classes now extend MutableCapbilities
new RemoteWebDriver(new ChromeOptions());
Deprecating constructors that don't take strongly-typed Options.
I am using selenium WebDriver 3.7.1 I am writing a code for firefox profile it will work on firefox version 57.0.2.
Step 1 : Create Firefox profile by type command "firebox.exe -p" create profile name as "myprofile".
Step 2 : follow the following code
System.setProperty("webdriver.gecko.driver","P:\\javaapi\\geckodriver-v0.19.1-win64\\geckodriver.exe");
DesiredCapabilities dc = DesiredCapabilities.firefox();
FirefoxProfile FF = new FirefoxProfile(new File("C:\\Users\\username\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\es610sjr.myprofile")); // path to firefox profile
dc.setCapability(FirefoxDriver.PROFILE, FF);
driver = new FirefoxDriver(dc);
driver.get("https://www.google.com");
Related
Can anyone help to create a profile and set options using firefox (gecko driver) to automatically download files in selenium webdriver - java. I have already searched a lot of options googling around, and nothing much worked. So posting my query on stack overflow. Please help with some code snippet if possible. This is for selenium 3 and firefox version 52.
Thanks in advance.
1/ create a new firefox profile manualy in firefox.exe -p
2/ run firefox with this new profile and set up to automaticly download PDF files
3/ use this:
#BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile selenium_profile = allProfiles.getProfile("NAME OF THE NEW FIREFOX PROFILE");
options.setProfile(selenium_profile);
options.setBinary("PATH TO FIREFOX.EXE");
System.setProperty("webdriver.gecko.driver", "PATH TO GECKODRIVER.EXE");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();
}
using existing custom firefox profile, you can run your test with almost any firefox setting modification (proxy setings, 1 imported certificate with no asking, extensions, etc.)
No more need to specify in code:
FirefoxProfile selenium_profile = new FirefoxProfile();
selenium_profile.setPreference...
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);