“无警报开放”在网站完全打开之前尝试放入登录凭据时 [英] "No Alert Open" when trying to put login credentials before the website is opened completely

查看:156
本文介绍了“无警报开放”在网站完全打开之前尝试放入登录凭据时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问网站,但是要首先访问网站我需要输入用户名和密码,之后完整的网站将会打开。当我尝试通过alert.sendkeys发送用户名和密码时,它会显示No alert open错误。请注意,只有在您首先输入用户名和密码然后单击登录进行授权时才会打开网站。我的浏览器是chrome,版本:64,Chrome驱动程序版本是:2.38。这是我的代码:

I 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:Password@Example.com); 如果网站使用基本身份验证,则应该这样做。

driver.get("http://UserName:Password@Example.com"); should do the trick if the site uses basic authentication.

特别说明:如果您的密码中有@,请不要忘记用%40

Special note: if you have @ in your password, don't forget to replace that bad boy by a %40

如果您的身份验证服务器需要域名为domainuser的域名,则需要在网址中添加双斜杠/:
// localdomain\user:password@example.com

In case your authentication server requires username with domain like "domainuser" you need to add double slash / to the url: //localdomain\user:password@example.com

编辑:

Chrome 59已取消支持 https:// user:password@example.com网址。

Chrome 59 has removed support for https://user:password@example.com URLs.

您可以使用以下方法在 IE中处理硒3.4

You can use the following method to handle it in IE as of selenium 3.4

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

有办法处理这个使用Chrome扩展程序。更多可在此处找到解释

There is way of handling this using Chrome extension. More explanation can be found here

将您的Chrome版本降级至< 59

Downgrade your chrome version to <59

这篇关于“无警报开放”在网站完全打开之前尝试放入登录凭据时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆