2

I am coming from Ruby background, I know how to do this in Ruby Selenium Binding, but I don't know how to do it Java Selenium Binding,

I have this code to create Firefox profile

 FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
 WebDriver driver=new FirefoxDriver(firefoxProfile);

It works in selenium 2.53 but it's throws error in very recent selenium binding 3.11.0, Can anyone tell me what's the alternative?

And also I wanted to switch off the marionette to connect to Legacy Firefox driver, I can do this with the following code

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", false);
WebDriver driver=new FirefoxDriver(capabilities);

But if I use the above line, then it gives the FirefoxDriver is deprecated. Can anyone guide me how to create profile as well as how to switch off the marionette?

Rajagopalan
  • 5,465
  • 2
  • 11
  • 29

2 Answers2

6

Yes FirefoxDriver(desiredCapabilities) is deprecated.

Alternate way would be to go with options:

FirefoxOptions foptions =  new FirefoxOptions(capabilities);
WebDriver driver=new FirefoxDriver(foptions);  

Update : [In order]

FirefoxOptions foptions =  new FirefoxOptions();
FirefoxProfile firefoxProfile = new FirefoxProfile(pathToProfile);
foptions.setProfile(firefoxProfile);
foptions.setCapability("marionette", false);
foptions.setBinary("C:\\Program Files\\Mozilla Firefox 52\\firefox.exe"); 
WebDriver driver = new FirefoxDriver(foptions);
Rajagopalan
  • 5,465
  • 2
  • 11
  • 29
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
1

To use an existing Firefox Profile for your Test Execution first you have to create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows. Now you have to pass the Firefox Profile to a FirefoxOptions class object. Additionally as you would be using the Legacy Firefox Browser you have to set marionatte to false through a DesiredCapabilities class object which you need to merge() into the FirefoxOptions class object as follows :

System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(testprofile);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("marionatte", false);
options.merge(dc);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

Update

I am not sure about your usecase and why you want to use Legacy Firefox Driver. But as per the GitHub discussion Unable to Start Firefox Using the Legacy Driver on a 3.5.3 Grid @jimevans clearly mentions :

The legacy Firefox driver won't work with Firefox 53 or so. You might get the browser to launch, but the language bindings will be entirely unable to communicate with the driver (because Firefox will refuse to load the browser extension that is the legacy Firefox driver).

@barancev also mentions :

A binding should not pass OSS capabilities in W3C-compliant parts of payload, in "capabilities" block. They are allowed in "desiredCapabilities" block only. Perhaps, Mozilla broke Selenium compatibility in Firefox 48 in release channel, but restored it in version 52 in esr channel. It was unexpected, but it's true.

It's all upto you to take a informed descission.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • First line is not necessary,right? because we are using Legacy driver? – Rajagopalan May 04 '18 at 10:06
  • But If have to use Legacy driver, then first line is not necessary, eh? – Rajagopalan May 04 '18 at 10:08
  • @Rajagopalan _Legacy Driver_ will not require the first line but in absence of _GeckoDriver_ I am not sure if _Legacy Driver_ will be compatible with _Selenium 3.11.0_ and functions e.g. `merge()`. Update me the status please. – undetected Selenium May 04 '18 at 10:17
  • I have been using WATIR which is using recent Ruby Selenium Binding, it works fine for me. – Rajagopalan May 04 '18 at 10:37
  • @Rajagopalan Won't comment on `watir`implementation. I have added an update with the comments from _Selenium Committers_ of the _Selenium Factory_. Keep me updated about the status. – undetected Selenium May 04 '18 at 10:42
  • You are right, selenium legacy driver wouldn't work from 48 version onwards, but ESR version of firefox still has the legacy driver inside. So switching is still possible. – Rajagopalan May 04 '18 at 10:57
  • You asked me why I go for legacy driver, this question is one of the example, Legacy runs fine but geckodriver wouldn't. https://stackoverflow.com/questions/50186199/not-able-to-select-option-open-link-in-new-tab-in-right-click-using-selenium – Rajagopalan May 05 '18 at 06:46
  • @Rajagopalan I have been observing all of your comments/answers/questions of late. IMO, you are trying to walk down the lane too fast. Take your own time to go through the documentation and discussions on stackoverflow. If you have a question feel free to raise a ticket. But please don't jump the gun as in **Legacy runs fine but geckodriver wouldn't**. It's **counter productive** for the future readers. – undetected Selenium May 05 '18 at 06:56
  • I am not against geckodriver if it completely works like legacy driver but it's missing many of it's feature. I have raised a ticket as well for geckodriver problem, read here github.com/mozilla/geckodriver/issues/960 ! I have explained you the main difference between implicit wait and explicit wait in your commnent, I hope you must have seen it. – Rajagopalan May 05 '18 at 07:17