Based on the error message mentioned in the question description, it seems like the issue is with the constructor that you are using to create the Firefox driver object.
To resolve this issue, you can try using the FirefoxOptions
class instead of the FirefoxDriver
class to launch the Firefox browser with a custom profile. Below is a code snippet that shows how to create a custom Firefox profile and launch the browser using the FirefoxOptions
class in Java:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
public class LaunchFirefoxCustomProfile {
public static void main(String[] args) {
// Define path to Firefox profile
String profilePath = "C:\\Users\\user\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\myprofile";
// Create Firefox profile object
FirefoxProfile profile = new FirefoxProfile(profilePath);
// Create Firefox options object and set profile
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
// Set geckodriver path
System.setProperty("webdriver.gecko.driver", "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
// Launch Firefox browser with custom profile
WebDriver driver = new FirefoxDriver(options);
// Navigate to a website
driver.get("https://www.example.com");
}
}
In the code above, we first define the path to the Firefox profile that we want to use. Then, we create a FirefoxProfile
object using this path. Next, we create a FirefoxOptions
object and set the profile using the setProfile()
method. Finally, we launch the Firefox browser using the FirefoxOptions
object.
I hope this helps! If you would like to learn more about launching Firefox with a custom profile using geckodriver
, I recommend checking out the following resources: