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());
}
}
CodePudding user response:
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");
File pathBinary = new File("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());
CodePudding user response:
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");