selenium-webdriver 的 HTTP 基本身份验证和代理(ruby 绑定)
我正在尝试使用 selenium-webdriver [ruby 绑定][1] 访问需要配置代理和 HTTP 基本身份验证的内部网站。
我目前有:
require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://my-internal-site.com"
但是由于代理和 http 身份验证问题,这失败了。如果我将用户名和密码添加到 URL(即 http://username: [电子邮件受保护]
)我可以在另一个不需要代理的网站上进行基本身份验证,但这似乎不是一个理想的解决方案。
有什么建议吗?
I'm attempting to use the selenium-webdriver [ruby bindings][1] to access an internal web-site that requires a proxy to be configured, and HTTP Basic Auth.
I currently have:
require "selenium-webdriver"
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://my-internal-site.com"
But this fails due to both the proxy and http auth issues. If I add my username and password to the URL (i.e. http://username:[email protected]
) I can do basic authentication on another site that doesn't require the proxy, but this doesn't seem like an ideal solution.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是
http://username:[电子邮件受保护]< /code> 一直是标准的做法,但越来越多的浏览器阻止这种方法。 BrowserMob 的 Patrick Lightbody 在公司中讨论 博客介绍他们如何让它发挥作用。
Unfortunately doing
http://username:[email protected]
has been the standard way of doing but with more and more browsers blocking this approach. Patrick Lightbody of BrowserMob discussed in the company blog on how they get it to work.在 WebDriver(或 Selenium)的浏览器完全支持此功能之前,替代选择是集成桌面 GUI 自动化工具,其中桌面 GUI 工具将自动执行 HTTP 身份验证部分。如果您在 google 上搜索“Selenium AutoIt”等内容,您可能会找到一些有关此内容或文件下载、上传的示例。
对于跨平台解决方案,请将 AutoIt 替换为 Sikuli 或类似的内容。
Until there is full support for this across browsers for WebDriver (or Selenium), alternate option is to integrate w/ desktop GUI automation tools, where the desktop GUI tool will automate the HTTP authentication part. You can probably find some examples for this or file downloads, uploads if you google for things like "Selenium AutoIt", etc.
For a cross platform solution, replace AutoIt with Sikuli or something similar.
我尝试了 AutoIt 的方法,直到 Selenium 2.18.0 为止它都工作得很好,
因为他们实现了UnhandledAlertException,一旦发生就会抛出
弹出代理登录对话框。
如果你尝试捕获它,你最终会得到 driver=null,你需要循环
尝试创建一个驱动程序并信任您的 AutoIt 脚本来终止该窗口。
I tried the approach with AutoIt and it worked fine until Selenium 2.18.0,
because they implemented UnhandledAlertException, which will be thrown as soon
as the proxy login dialog pops up.
if you try to catch it, you end up with an driver=null, you would need to loop
the attempt to create a driver and trust into your AutoIt Script to kill the window.
如果您使用的是
Google-Chrome
,请尝试创建自定义扩展程序并通过ChromeOptions
导入它。它支持 Chrome 中的browsermob_proxy
不支持的http(s)
。在重定向测试的情况下,这是目前唯一可以帮助您的方法...有关详细信息,请查看这篇文章
https://devopsqa .wordpress.com/2018/08/05/handle-basic-authentication-in-selenium-for-chrome-browser/
If you're using
Google-Chrome
, try creating a custom extension and import it throughChromeOptions
. It supportshttp(s)
that wasn't supported bybrowsermob_proxy
in Chrome. In-case of redirects testing, this is the only way that will help you as of now...For details, check this post
https://devopsqa.wordpress.com/2018/08/05/handle-basic-authentication-in-selenium-for-chrome-browser/