0

My problem is Firefox. I installed a different location. But I tried this solution isn't working for me.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxProfile;

import java.io.File;

 public class firefoxDriver
{
public static void main(String[] args)
{
    File pathBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary ffBinary = new FirefoxBinary(pathBinary);
    FirefoxProfile ffProfile = new FirefoxProfile();

    // Add .exe file
    System.setProperty("webdriver.gecko.driver", "D:\\Docs\\Drivers\\geckodriver.exe");

    // Create Firefox object driver.
    WebDriver ffDriver = new FirefoxDriver(ffBinary, ffProfile);

    ffDriver.get("https://google.com");
    System.out.println(ffDriver.getTitle());

}

}

The error I get: Error

  • 1
    Please look at this solution maybe it will help you: https://stackoverflow.com/questions/49683355/cannot-resolve-constructor-firefoxdriverorg-openqa-selenium-firefox-firefoxprof – Tomasz Jędrzejczyk Sep 30 '21 at 14:14

3 Answers3

0

N.B - In your particular example you do not need to create a profile. New profile is created automatically by default. You use profiles when you have some pre-configured profiles persisted before you run your driver.

You can do this:

FirefoxOptions options = new FirefoxOptions();
options.setBinary(new FirefoxBinary(new File("...")));
options.setProfile(new FirefoxProfile(new File("...")));
WebDriver = new FirefoxDriver(options);

Another way to specify browser binary isto use system property:

System.setProperty(
    FirefoxDriver
        .SystemProperty.BROWSER_BINARY, "PATH_TO_YOUR_BINARY");

If you have a named profile set up for your instance of firefox browser, then you should do the following (like in previous case before you create a driver):

System.setProperty(
    FirefoxDriver
        .SystemProperty.BROWSER_PROFILE, "NAME_OF_PROFILE");
Alexey R.
  • 8,057
  • 2
  • 11
  • 27
  • Thank you for answer but I think I cannot coded properly, it not worked. System.setProperty("webdriver.gecko.driver", "D:\\exe"); System.setProperty(FirefoxDriver.SystemProperty.BROWSER_BINARY, "D:\\.exe"); FirefoxOptions ffOptions = new FirefoxOptions(); ffOptions.setBinary(new FirefoxBinary(new File("D:\\"))); ffOptions.setProfile(new FirefoxProfile(new File("D:\\"))); WebDriver ffDriver = new FirefoxDriver(ffOptions); ffDriver.get("https://google.com"); System.out.println(ffDriver.getTitle()); – Yekta Özdemir Sep 30 '21 at 15:08
  • Given model profile directory is not a directory: D:\Program Files\Mozilla Firefox\firefox.exe – Yekta Özdemir Sep 30 '21 at 15:11
  • I'm not getting what it means. Why are you setting `new File("D\\")` as path to binary? It is not even a file. And of course not a Firefox binary. – Alexey R. Oct 01 '21 at 06:24
  • I just shorted because of character limit. – Yekta Özdemir Oct 02 '21 at 10:10
0

There is not constructor that is overloaded to have binary and profile together. You should use options.

Code :

System.setProperty("webdriver.gecko.driver", "D:\\Docs\\Drivers\\geckodriver.exe");
String pathBinary = "D:\\Program Files\\Mozilla Firefox\\firefox.exe";
        
FirefoxOptions ffOptions = new FirefoxOptions();
FirefoxProfile ffProfile = new FirefoxProfile(pathBinary);
ffOptions.setProfile(ffProfile);
ffOptions.setBinary("C:\\Program Files\\Mozilla Firefox 52\\firefox.exe"); 
       
// Create Firefox object driver.
WebDriver ffDriver = new FirefoxDriver(ffOptions);

ffDriver.get("https://google.com");
System.out.println(ffDriver.getTitle());
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0
public static void main(String[] args)
{

    // Add .exe file
    System.setProperty("webdriver.gecko.driver", "D:\\Docs\\Drivers\\geckodriver.exe");
    File pathBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");

    FirefoxBinary ffBinary = new FirefoxBinary(pathBinary);
    DesiredCapabilities desired = DesiredCapabilities.firefox();
    FirefoxOptions ffOptions = new FirefoxOptions();
    desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, ffOptions.setBinary(ffBinary));

    // Create Firefox object driver.
    WebDriver ffDriver = new FirefoxDriver(ffOptions);

    ffDriver.get("https://google.com");
    System.out.println(ffDriver.getTitle());
}

I solved my problem with this method. I don't know there is a much more simple solution.