在网站完全打开之前尝试输入登录凭据时出现“无警报打开”

2024-03-21

enter image description hereI am trying to access a website, However to access the website first I need to enter username and password, After that full website will get open. When I try to send username and password through "alert.sendkeys", it gives error "No alert open". Please note website will only open when you have put the username and password first and then click on "Sign In" for authorization.My browser is chrome, version:64 and chrome driver version is :2.38. Here is my code:

public static void launchWebsite(String URL) {
        driver.get(URL);
        try {
            WebDriverWait wait = new WebDriverWait(driver, 2);
            wait.until(ExpectedConditions.alertIsPresent());
            Alert alert = driver.switchTo().alert();
            System.out.println(alert.getText());
           alert.sendKeys("website");
           alert.sendKeys("grren");

        } catch (Exception e) {
            System.out.println("No alertis present");
            //exception handling
        }
    }

driver.get("http://UserName:[email protected] /cdn-cgi/l/email-protection");如果网站使用基本身份验证,应该可以解决问题。

特别注意:如果您的密码中有@,请不要忘记将那个坏男孩替换为%40

如果您的身份验证服务器需要带有“domainuser”等域的用户名,您需要在 url 中添加双斜杠 /://localdomain\user:[email protected] /cdn-cgi/l/email-protection

EDIT:

Chrome 59 已取消支持对于 https://用户:[电子邮件受保护] URLs. https://www.chromestatus.com/feature/5669008342777856

可以使用下面的方法来处理IE 自 selenium 3.4 起

WebDriverWait wait = new WebDriverWait(driver, 10);      
Alert alert = wait.until(ExpectedConditions.alertIsPresent());     
alert.authenticateUsing(new UserAndPassword(username, password));

有办法处理这个问题使用 Chrome 扩展程序 https://gist.github.com/florentbr/25246cd9337cebc07e2bbb0b9bf0de46. More 可以在这里找到解释 https://stackoverflow.com/a/44679605/5074293

OR

将您的 chrome 版本降级至

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在网站完全打开之前尝试输入登录凭据时出现“无警报打开” 的相关文章

随机推荐