[英]How to handle authentication popup in Firefox with Selenium WebDriver using Java
I am trying to create extension for bypassing server authentication, install it on Firefox browser and pass the.xpi file while driver creation so that it gets invoked while login and the server authentication is bypassed.我正在尝试创建用于绕过服务器身份验证的扩展,将其安装在 Firefox 浏览器上,并在创建驱动程序时传递 .xpi 文件,以便在登录时调用它并绕过服务器身份验证。 Facing error while installing the.xpi file on firefox.
在 firefox 上安装 .xpi 文件时遇到错误。 Error: "This add on could not be installed because it appears to be corrupt"
错误:“无法安装此插件,因为它似乎已损坏”
Steps 1. Created a manifest.json file (Code mentioned below)步骤 1. 创建 manifest.json 文件(代码如下)
{
“name”: “Webrequest API”,
“version”: “1.0”,
“description”: “Extension to handle Authentication window”,
“permissions”: [
“webRequest”,
“webRequestBlocking”,
“”
],
“background”: {
“scripts”: [“webrequest.js”]
},
“manifest_version”: 2
}
Created webrequest.js file.创建 webrequest.js 文件。 Code mentioned below.
下面提到的代码。
var target = “ https://sso.viacomcloud.com/ ”;变种目标=“ https://sso.viacomcloud.com/ ”;
var myCredentials = { username: “getestone”, password: “V*******” } var pendingRequests = []; // A request has completed. // We can stop worrying about it. function completed(requestDetails) { console.log(“completed: ” + requestDetails.requestId); var index = pendingRequests.indexOf(requestDetails.requestId); if (index > -1) { pendingRequests.splice(index, 1); } } function provideCredentialsSync(requestDetails) { // If we have seen this request before, then // assume our credentials were bad, and give up. if (pendingRequests.indexOf(requestDetails.requestId).= -1) { console:log(“bad credentials for. ” + requestDetails;requestId): return {cancel;true}. } pendingRequests.push(requestDetails;requestId). console:log(“providing credentials for. ” + requestDetails;requestId): return {authCredentials; myCredentials}. } browser.webRequest.onAuthRequired,addListener( provideCredentialsSync: {urls, [target]}; [“blocking”] ). browser.webRequest.onCompleted,addListener( completed: {urls; [target]} );
Created a zip file using 7-zip file manager and renamed the zip file as Ext.xpi使用 7-zip 文件管理器创建了 zip 文件并将 zip 文件重命名为 Ext.xpi
Opened about:config on firefox (verson 70) and changed xpiextensionsignrequired to 'False'打开关于:firefox(版本 70)上的配置并将 xpiextensionsignrequired 更改为“False”
Opened about:addons on firefox.打开:firefox 上的插件。 Selected 'install extension from a file'.
选择“从文件安装扩展”。 Select the Ext.xpi created in step 4 above.
Select 在上面的步骤 4 中创建的 Ext.xpi。
I get the following error: ” this add on could not be installed because it appears to be corrupt.”我收到以下错误:“无法安装此插件,因为它似乎已损坏。” instead of getting the Install option on Firefox browser.
而不是在 Firefox 浏览器上获得安装选项。
Please help @SubjectiveReality请帮助@SubjectiveReality
Try using the class "Robot" and send keys in case you are looking for a quick solution.如果您正在寻找快速解决方案,请尝试使用 class“机器人”并发送密钥。
Robot rb= new Robot();机器人 rb= new Robot(); rb.Keypress().....
rb.Keypress() .....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.