Cannot set a default profile for the Firefox in Selenium Webdriver 3, because there is no such constructor in the FirefoxDriver class.
Code:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class SeleniumStartTest {
@Test
public void seleniumFirefox() {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\FirefoxDriver\\geckodriver.exe");
ProfilesIni profileIni = new ProfilesIni();
FirefoxProfile profile = profileIni.getProfile("default");
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.google.com");
}
}
Java code a compile error: Java Code
Maven pom.xml dependencies: Selenium 3.14.0
Firefox version: Firefox version 62.0.2
move your setup to
@BeforeClass
I'm using this setup, works just fine:
just change paths and profile designation.
As you are using Selenium 3.14.0 as per the FirefoxDriver Class the valid constructors are:
FirefoxDriver()
FirefoxDriver(FirefoxOptions options)
FirefoxDriver(GeckoDriverService service)
FirefoxDriver(GeckoDriverService service, FirefoxOptions options)
FirefoxDriver(XpiDriverService service)
FirefoxDriver(XpiDriverService service, FirefoxOptions options)
So, as per your code attempts the following is not a valid option to invoke
FirefoxDriver()
Solution
To invoke invoke
FirefoxDriver()
with the default profile you need to use thesetProfile(profile)
method to set the FirefoxProfile through an instance ofFirefoxOptions()
and you can use the following code block:Code Block:
Console Output: