如何解决“没有这样的警报” - c# selenium chromedriver 中的身份验证提示应用程序错误
我收到类似“没有此类警报”的错误消息。在尝试切换身份验证弹出窗口时。我添加了“UnhandledPromptBehavior.Ignore”并给线程等待直到提示加载。鉴于 url 的详细信息,我不想绕过这个 propmt。因为,有这样的需要。谢谢
注意:在代码执行之前,提示加载到浏览器上。
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore;
Driver = new ChromeDriver(@"D:\Drivers",chromeOptions);
Driver.Navigate().GoToUrl("http://localhost:8019/");
Thread.Sleep(6000);
IAlert alert = Driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("123","12333");
解决方法
这不是来自网站的警报,而是浏览器提示。您可以使用 switch 来提醒仅使用 alert() 等方法从 websit 脚本抛出的警报
由于它是浏览器级别的窗口,因此您无法通过 selenium 处理它。您应该使用任何其他工具,如 Silkuli、autoit 等
您也可以直接从 url 进行身份验证以避免弹出:
如果你的网址是这样的
改成:
url = "https://username:password@yoururl.com"
driver.get(url)
,
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Ignore;
Driver = new ChromeDriver(@"D:\Drivers",chromeOptions);
Driver.Navigate().GoToUrl("http://username:password@localhost:8019/");
Thread.Sleep(6000);
如果您的用户名123和密码是12333
网址为
Driver.Navigate().GoToUrl("http://123:12333@localhost:8019/");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。