0

I am using :

  • latest version of gecko driver ("0.32.2").
  • recent version of firefox ("102.7.0esr (64 bits))

enter image description here

I set up the executables like this :

System.setProperty("webdriver.gecko.driver", "C:\\Dev\\tools\\geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "C:\\Dev\\tools\\MyCompanyFirefox\\firefox.exe");

WebDriver driver = new FirefoxDriver();

And I get :

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Caused by: org.openqa.selenium.WebDriverException: 
Driver server process died prematurely.
Build info: version: '4.1.4', revision: '535d840ee2'
System info: host: 'GLA6008818', ip: '172.17.134.204', os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.6'
Driver info: driver.version: FirefoxDriver
Tristan
  • 8,733
  • 7
  • 48
  • 96
  • try setting path to Firefox executable without the double "\\" In this case not sure you need to escape. – pcalkins Mar 16 '23 at 17:42
  • Yes, I do. That's how java works and that's how geckodriver path is successfully found. – Tristan Mar 16 '23 at 19:27
  • Do you have anything already running on localhost? – pcalkins Mar 16 '23 at 20:43
  • wouldn'tya know I just had this error popup randomly... I'm not running Windows 11 or JRE 17. It seemed to disappear on the next run though. Does this happen consistently for you? – pcalkins Mar 17 '23 at 17:36
  • Indeed, very consistent, I think I have a custom ESR version or maybe some admin setup prevents me to automate this enterprise Firefox. And I can't find any "portable" Firefox to unzip. – Tristan Mar 18 '23 at 18:51
  • Just a wild guess really, but it might be caused by Firefox trying to download/install an update. (even the ESR versions will patch security issues...) You might try just turning off auto-updates or running it manually and applying the updates. – pcalkins Mar 20 '23 at 17:42
  • So you confirme there is no "portable" version of Firefox which doesn't need to run a ".exe" ? – Tristan Mar 21 '23 at 10:41
  • Since it's open-source, I'd guess there is a version out there that doesn't need an installer to run. It's still probably going to setup some things on the first run that are per-user. At that point though you probably won't have a good test-case. – pcalkins Mar 21 '23 at 17:20
  • Chromium is available in a zip, but I can't start it on my secured professionnal PC, so yeah, I guess the policy running on my PC prevents me to use Selenium Webdriver. – Tristan Mar 22 '23 at 18:09
  • I guess you could confirm that by opening a command prompt, navigating to your firefox directory (something like: "C:\Program Files\Mozilla Firefox\"...) and typing "firefox.exe -marionette" This is how Selenium will launch it... and we can tell that your geckodriver was able to launch from the exception received. – pcalkins Mar 22 '23 at 20:07

1 Answers1

0

webdriver.firefox.bin is no more a valid property to be set through System.setProperty().


Solution

To explicitly set the location of the binary executable you need to use the setBinary() method through an instance of FirefoxOptions as follows:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class genericTestFirefox {

    public static void main(String[] args) {

        FirefoxOptions options = new FirefoxOptions();
        options.setBinary("C:\\Dev\\tools\\MyCompanyFirefox\\firefox.exe");
        WebDriver driver = new FirefoxDriver(options);
        driver.get("https://www.google.com/");
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352