如何使用Selify C#管理基本身份验证登录? [英] How to manage Basic Authentication login with selenium c#?
本文介绍了如何使用Selify C#管理基本身份验证登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("user","password");
alert.Accept();
但我收到以下错误:
Message: OpenQA.Selenium.NoAlertPresentException : no such alert
(Session info: chrome=87.0.4280.141)
如果我等待,我会超时,但什么都没有发生,正如您所看到的,我正在使用Chrome,我读到了几年前的一篇帖子,说Chrome不能管理警报,但我不知道这是否在今天是一个问题,我希望你们能帮助我。
http://user:password@mywebsite.com
经过几天的研究和尝试,这对我很管用,我做了一个Google Chrome扩展,推荐答案的基本身份验证方法不再起作用,所以我用我的凭据进行了这个扩展,这有点冒险,但这是我找到的唯一解决方案
首先您需要创建一个清单.json:
{
"name": "Webrequest API",
"version": "1.0",
"description": "Extension to handle Authentication window",
"permissions": [
"webRequest",
"webRequestBlocking",
"<all_urls>"
],
"background": {
"scripts": [
"webrequest.js"
]
},
"manifest_version": 2
}
然后您需要创建webquest.js:
chrome.webRequest.onAuthRequired.addListener(function(details){
console.log("chrome.webRequest.onAuthRequired event has fired");
return {
authCredentials: {username: "myusername", password: "mypassword"}
};
},
{urls:["<all_urls>"]},
['blocking']);
之后,您需要在开发者模式下的Chrome://扩展站点中创建CRX,之后您应该可以毫无问题地登录到您正在尝试登录的网站。
参考文献: How to handle authentication popup in Chrome with Selenium WebDriver using Java我希望对任何来到这篇文章的人有所帮助
这篇关于如何使用Selify C#管理基本身份验证登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文