无法使用 ruby​​ selenium webdriver 连接到浏览器 [英] Unable to connect to browser using ruby selenium webdriver

查看:32
本文介绍了无法使用 ruby​​ selenium webdriver 连接到浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 ruby​​ selenium webdriver 运行一些基本的自动化测试.相同的代码在我的家用计算机上运行良好,但在我的工作计算机上运行失败,它位于代理后面(不需要身份验证).

I tried to run some basic automated tests using ruby selenium webdriver. The same code works perfectly on my home computer, but fails on my work computer which is behind a proxy (which doesn't require authentication).

driver = Selenium::WebDriver.for :firefox, :profile => 'default'

driver = Selenium::WebDriver.for :firefox, :profile => 'default'

我得到的错误是:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.24.0/lib/selenium/webdriver/remote/http/common.rb:66:in `create_response': unexpected response, code=
403, content-type="text/html" (Selenium::WebDriver::Error::WebDriverError)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>ERROR</H1>
<H2>The requested URL could not be retrieved</H2>
<HR noshade size="1px">
<P>
While trying to retrieve the URL:
<A HREF="http://127.0.0.1:7055/hub/session">http://127.0.0.1:7055/hub/session</A>
<P>
The following error was encountered:
<UL>
<LI>
<STRONG>
Access Denied.
</STRONG>
<P>
Access control configuration prevents your request from
being allowed at this time.  Please contact your service provider if
you feel this is incorrect.
</UL>

浏览器以正确的配置文件打开,但生成的驱动程序变量为零.我什至尝试在配置文件上手动设置代理,但没有运气.

The browser opens with correct profile, but resulting driver variable is nil. I even tried to manually setup the proxy on the profile with no luck.

有什么想法吗?

推荐答案

您的环境中可能设置了 HTTP_PROXY(或 http_proxy).selenium-webdriver (2.25) 的下一个版本也将支持 NO_PROXY/no_proxy(然后您可以将其设置为 NO_PROXY=127.0.0.1).在此之前,您可以在启动浏览器之前从 Ruby 环境中删除代理:

You probably have HTTP_PROXY (or http_proxy) set in your environment. The next release of selenium-webdriver (2.25) will also honor NO_PROXY/no_proxy (which you can then set to NO_PROXY=127.0.0.1). Until then you can remove the proxy from the Ruby environment before launching the browser:

ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
driver = Selenium::WebDriver.for :firefox

如果您需要为 Firefox 配置代理与外界通信,您可以尝试如下操作:

If you need the proxy configured for Firefox to communicate with the outside world, you could try something like this:

proxy = Selenium::WebDriver::Proxy.new(:http => ENV['HTTP_PROXY'] || ENV['http_proxy'])
ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
driver = Selenium::WebDriver.for :firefox, :proxy => proxy

这篇关于无法使用 ruby​​ selenium webdriver 连接到浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆