How to perform Basic Authentication for FirefoxDriver, ChromeDriver and IEdriver in Selenium WebDriver?

前端 未结 7 1146
一个人的身影
一个人的身影 2020-11-27 16:46

I am using the Selenium-Firefox-driver and Selenium-Chrome-Driver version 2.0a5 (Web Driver API), and I am trying to test a web app that h

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 17:07

    For more portability, this can be handled by stub API and using Alert.

    Example Java code (sample):

    import org.openqa.selenium.Alert;
    import org.openqa.selenium.security.Credentials;
    public void authenticateUsing(Credentials credentials) {
        private final Alert alert;
        alert.authenticateUsing(credentials);
    }
    

    See also: auth_tests.py

    Or by sending keys manually like:

    SendKeys("user");
    SendKeys("{TAB}");
    SendKeys("password");
    SendKeys("~"); // Enter
    

    See also the following feature request: #453 Portable BASIC Auth at GitHub

    Related:

    • How to send Basic Authentication headers in Selenium? at QA SE

提交回复
热议问题