Selenium - Basic Authentication via url

后端 未结 5 2038
时光说笑
时光说笑 2020-11-22 01:02

In my Selenium-Test (with chromedriver-2.24) I\'m trying to access my webpage via basic authentication with the following statement:



        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 01:10

    Florent B.'s approach of calling .get on the URL twice worked for me with a slight modification. In JS:

    driver
            .get('http://admin:admin@localhost:8080')
            .then( () => driver.get('http://localhost:8080') )
    

    working on google chrome 62.0.3202.94 with ChromeDriver 2.33.506092 and the approach seems compatible with firefox 56.0.2 with geckodriver 0.19.1, and phantomjs 2.1.1 all under Debian linux 9.

    What I believe is happening is the first call sets up the Authorization header sent by the browser. The second call removes the credentials from the URL and the credentials no longer are applied to subresources. The then synchronizes the two requests ensuring order.

提交回复
热议问题