HTTP Basic Auth via URL in Firefox does not work?

后端 未结 8 2124
悲&欢浪女
悲&欢浪女 2020-11-30 02:18

I know that normally you can login to sites that require HTTP basic authentication with Selenium by passing the username and password in the URL, e.g.:

sele         


        
8条回答
  •  天命终不由人
    2020-11-30 02:55

    Add a slash after the context root:

    Instead of: selenium.open("http://myusername:myuserpassword@mydomain.com/mypath");

    use: selenium.open("http://myusername:myuserpassword@mydomain.com/mypath/");

    It makes all the difference of the world adding the slash at the end of the context root. Without the slash, the popup opens, with the slash it gets authenticated as expected.

    Note, that this is not a selenium bug or whatnot, but a firefox thing. You can use your command line as well to see for yourself:

     C:\Program Files\Mozilla Firefox>firefox http://myusername:myuserpassword@mydomain.com/mypath/
    

    For me, it works even without settings the networks uris:

    FirefoxProfile profile = new FirefoxProfile();
    //profile.setPreference("network.automatic-ntlm-auth.trusted-uris", "mydomain.com");
    //profile.setPreference("network.negotiate-auth.trusteduris", "mydomain.com");
    
    WebDriver driver = new FirefoxDriver(profile);
    
    driver.navigate().to("http://myusername:myuserpassword@mydomain.com/mypath/");
    


    versions
    Firefox 19.0,
    selenium-java 2.31.0

提交回复
热议问题