我正试图用Google运行一个硒测试。我希望使用HTTP基本身份验证来登录。这不是在Selenium中实现的,所以建议加载一个扩展。我使用的代码是
https://github.com/RobinDev/Selenium-Chrome-HTTP-Private-Proxy和the answer to "How to override basic authentication in selenium2 with Java using chrome driver?"
我试着使它适应我的需要。
更新
检查最低工作示例。
git clone git@github.com:alexbiddle/selenium-chrome-http-basic-auth.git节选如下
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "https",
host: "subdomain.example.com"
},
bypassList: ["foobar.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "example",
password: "abc123"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);在Java中使用
ChromeOptions chromeOptions = new ChromeOptions();
File proxyPath = new ClassPathResource("proxy.zip").getFile();
chromeOptions.addExtensions(proxyPath);
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CAPABILITY, chromeOptions);
webDriver = new ChromeDriver(capability);我在https://developer.chrome.com/extensions/proxy#type-ProxyServer上反复检查了文档,以防缺少某物的值,但是当用URL加载测试时。
https://subdomain.example.com它失败了
ERR_TUNNEL_CONNECTION_FAILED我在Mac上用Chrome。
发布于 2017-06-14 08:42:55
错误很可能是由扩展定义的代理造成的。
如果需要与系统不同的扩展,则应该在没有代理的情况下构建扩展,并在功能中定义代理。
要创建扩展名,只需使用在username和password中定义的凭据压缩下面的文件
manifest.json:
{
"manifest_version": 2,
"name": "Authentication for ...",
"version": "1.0.0",
"permissions": ["<all_urls>", "webRequest", "webRequestBlocking"],
"background": {
"scripts": ["background.js"]
}
}background.js:
var username = "my-username";
var password = "my-password";
chrome.webRequest.onAuthRequired.addListener(
function handler(details) {
if (username == null)
return {cancel: true};
var authCredentials = {username:username, password: username};
username = password = null;
return {authCredentials: authCredentials};
},
{urls: ["<all_urls>"]},
['blocking']
);发布于 2017-06-14 02:12:10
Suggestion#1:
如果您的互联网连接有一些代理设置,这限制了加载网站,那么您可以收到错误111:Net::ERR_TUNNEL_CONNECTION_FAILED中的铬。必须禁用代理设置才能解决此错误。
本教程中的图片一步一步地给出整个过程:failed-error-google-chrome/
Suggestion#2:
Yakub K还建议您禁用代理设置和检查。
按照以下步骤禁用代理: 打开Internet Explorer。 单击“工具”按钮,然后单击“Internet选项”。 单击“连接”选项卡,然后单击“局域网设置”。 取消选中“为局域网使用代理服务器”的复选框。 点击OK。
资源链接:7-ecoms/error-errtunnelconnectionfailed-when-trying-to/8af1b8ed-86fe-461f-a629-9a6f23ce857e
发布于 2019-06-11 13:59:13
System.setProperty("webdriver.chrome.driver", "C:\\Users\\singh\\OneDrive\\Documents\\Selenium\\chromedriver.exe");
Robot rb = new Robot();
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C:\\Users\\singh\\OneDrive\\Documents\\Selenium\\Extension\\extension.crx"));
WebDriver driver = new ChromeDriver(options);
rb.keyPress(KeyEvent.VK_F5);
driver.navigate().to("https://stage.creativememories.com");经过几天的严格研究,这是对我有效的明确答案。希望这能帮到你。
步骤:
https://stackoverflow.com/questions/44458165
复制相似问题