0

Is it possible to pass Username and password through URL in Firefox browser for Selenium 4.0.0 version? I am able to pass through selenium 3.141.59 version but not able to pass through Selenium 4 version. Also I can able to pass to Chrome and edge browser using Dev tools concept.

Sample Code I used is:

FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
options.setCapability("build", "Testing Firefox Options [Selenium 4]");
options.setCapability("name", "Testing Firefox Options [Selenium 4]");
options.setCapability("platformName", "Windows 10");
options.setCapability("browserName", "Firefox");
options.setCapability("browserVersion", "95.0");
try {
driver = new RemoteWebDriver(new URL("http://" + username + ":" + Password+ 
"@hub.lambdatest.com/wd/hub"), ((Capabilities) options));
} catch (MalformedURLException e) {
System.out.println("Invalid grid URL");
}driver.get("https://www.lambdatest.com");

While using the code snippet, I am not able to create any new session in Firefox. I want to be like: http://username:password@the-site.com

Is there any way to do this or does selenium 4 doesn't support this functionality in Firefox browser?

djmonki
  • 3,020
  • 7
  • 18

1 Answers1

0

DesiredCapabilities is now deprecated in v4.x.x, capabilities are now W3C compliant and wrap your vendor options with the appropriate prefix (in this case it is LT:Options for lambdatest.com)

Remediate to the following:

public void setUp() throws Exception {
    FirefoxOptions options = new FirefoxOptions();
    options.setAcceptInsecureCerts(true);
    options.setPlatformName("Windows 10");
    options.setBrowserVersion("95.0");

    HashMap<String, Object> ltOptions = new HashMap<String, Object>();
    ltOptions.put("build", "Testing Firefox Options [Selenium 4]");
    ltOptions.put("name", "Testing Firefox Options [Selenium 4]");
    ltOptions.put("browserName", "Firefox");
    options.setCapability("LT:Options", ltOptions);

    try {
        driver = new RemoteWebDriver(new URL("http://" + username + ":" + Password + "@hub.lambdatest.com/wd/hub"), options);
    } catch (MalformedURLException e) {
        System.out.println("Invalid grid URL");
    }

    driver.get("https://www.lambdatest.com");
}
djmonki
  • 3,020
  • 7
  • 18
  • Thanks for the information, but this code also gets same log error "Could not create new session". Is there anyway to create new session in Firefox browser for Selenium 4.0.0 version ? – Kavya KS Jan 07 '22 at 04:56
  • I rushed my answer, there are few other changes and have edited based on you requirement of Selenium 4 and you are using lambdatest – djmonki Jan 08 '22 at 03:12
  • lambdatest is just a demo URL, But my requirement is same that I want to pass username and password through url in Firefox browser – Kavya KS Jan 11 '22 at 05:13