Alert.Authenticate和Alert.setCredentials之间的区别

时间:2016-10-20 15:19:26

标签: selenium selenium-webdriver

"driver.switchTo().alert().Authenticate()""driver.switchTo().alert().setCredentails()"之间有什么区别?两者都使用Interface Credentials。

1 个答案:

答案 0 :(得分:2)

身份验证在设置凭据后调用接受。它可以在消息来源中找到。

    public void setCredentials(Credentials credentials) {
        if(!(credentials instanceof UserAndPassword)) {
            throw new RuntimeException("Unsupported credentials: " + credentials);
        } else {
            UserAndPassword userAndPassword = (UserAndPassword)credentials;
            RemoteWebDriver.this.execute("setAlertCredentials", ImmutableMap.of("username", userAndPassword.getUsername(), "password", userAndPassword.getPassword()));
        }
    }


    public void authenticateUsing(Credentials credentials) {
        this.setCredentials(credentials);
        this.accept();
    }