本机安装好Ruby + Watir环境后,在CMD中敲入irb执行下面的程序
require 'rubygems' require 'watir' require 'watir-webdriver' ie=page = Watir::Browser.new :ie ie.goto "www.google.com"
在执行 ie=page = Watir::Browser.new :ie 的报下面错误
C:Userszxy>irb DL is deprecated, please use Fiddle irb(main):001:0> require 'rubygems' => false irb(main):002:0> require 'watir' => true irb(main):003:0> require 'watir-webdriver' => true irb(main):004:0> ie=page = Watir::Browser.new :ie Started InternetExplorerDriver server (64-bit) 2.37.0.0 Listening on port 5555 Selenium::WebDriver::Error::WebDriverError: unexpected response, code=502, content-type="text/html" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>????????????</TITLE> <META http-equiv=Content-Type content="text/html; charset=UTF-8"> <STYLE id=L_default_1>A { FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: #005a80; FONT-FAMILY: ?????? } A:hover { FONT-WEIGHT: bold; FONT-SIZE: 9pt; COLOR: #0d3372; FONT-FAMILY: ?????? } TD { FONT-SIZE: 9pt; FONT-FAMILY: ?????? } TD.titleBorder { BORDER-RIGHT: #955319 1px solid; BORDER-TOP: #955319 1px solid; PADDING-LEFT: 8px; FONT-WEIG HT: bold; FONT-SIZE: 12pt; VERTICAL-ALIGN: middle; BORDER-LEFT: #955319 0px solid; COLOR: #955319; B ORDER-BOTTOM: #955319 1px solid; FONT-FAMILY: ??????; HEIGHT: 35px; BACKGROUND-COLOR: #d2b87a; TEXT- ALIGN: left } TD.titleBorder_x { BORDER-RIGHT: #955319 0px solid; BORDER-TOP: #955319 1px solid; PADDING-LEFT: 8px; FONT-WEIG HT: bold; FONT-SIZE: 12pt; VERTICAL-ALIGN: middle; BORDER-LEFT: #955319 1px solid; COLOR: #978c79; B ORDER-BOTTOM: #955319 1px solid; FONT-FAMILY: tahoma; HEIGHT: 35px; BACKGROUND-COLOR: #d2b87a; TEXT- ALIGN: left } .TitleDescription { FONT-WEIGHT: bold; FONT-SIZE: 12pt; COLOR: black; FONT-FAMILY: ?????? } SPAN.explain { FONT-WEIGHT: normal; FONT-SIZE: 9pt; COLOR: #934225 } SPAN.TryThings { FONT-WEIGHT: normal; FONT-SIZE: 9pt; COLOR: #934225 } .TryList { MARGIN-TOP: 5px; FONT-WEIGHT: normal; FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: ?????? } .X { BORDER-RIGHT: #955319 1px solid; BORDER-TOP: #955319 1px solid; FONT-WEIGHT: normal; FONT-SI ZE: 12pt; BORDER-LEFT: #955319 1px solid; COLOR: #7b3807; BORDER-BOTTOM: #955319 1px solid; FONT-FAM ILY: ??????; BACKGROUND-COLOR: #d1c2b4 } .adminList { MARGIN-TOP: 2px } </STYLE> <META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD> <BODY bgColor=#f3f3ed> <TABLE cellSpacing=0 cellPadding=0 width="100%"> <TBODY> <TR> <TD class=titleborder_x width=30> <TABLE height=25 cellSpacing=2 cellPadding=0 width=25 bgColor=black> <TBODY> <TR> <TD class=x vAlign=center align=middle>X</TD> </TR> </TBODY> </TABLE> </TD> <TD class=titleBorder id=L_default_2>??????????????????:<SPAN class=TitleDescription> ?????????? ????????</SPAN> </TD> </TR> </TBODY> </TABLE> <TABLE id=spacer> <TBODY> <TR> <TD height=10></TD></TR></TBODY></TABLE> <TABLE width=400> <TBODY> <TR> <TD noWrap width=25></TD> <TD width=400><SPAN class=explain><ID id=L_default_3><B>??????:</B></ID></SPAN><ID id=L_default_ 4> ???????????????????????????????????????????????????????????? </ID><BR><BR> <B><SPAN class=tryThings><ID id=L_default_5><B>????????????:</B></ID></SPAN></B> <UL class=TryList> <LI id=L_default_6><B>?????????:</B> ??????????????????????????????????????????????????????? ?????????????? Internet ?????????????????? <LI id=L_default_7><B>????????????:</B> ???????????????????????????????????????????????????????????? ????????????????????? <LI id=L_default_8><B>???????????????:</B> ????????????????????????????????????????????????????????? ?????????????????????????????? </UL> <ID id=L_default_9>????????????????????????????????????????????????????????????????????????????????? ??????</ID> <BR><BR> </TD> </TR> </TBODY> </TABLE> <TABLE id=spacer><TBODY><TR><TD height=15></TD></TR></TBODY></TABLE> <TABLE width=400> <TBODY> <TR> <TD noWrap width=25></TD> <TD width=400 id=L_default_10><B>????????????(?????????????????????)</B> <UL class=adminList> <LI id=L_default_11>????????????: 502 Proxy Error???The ISA Server denied the specified Unif orm Resource Locator (URL). (12202) <LI id=L_default_12>IP ??????: 10.45.11.233 <LI id=L_default_13>??????: 2013-12-16 7:36:25 [GMT] <LI id=L_default_14>?????????: ISA01 <LI id=L_default_15>???: ?????? </UL> </TD> </TR> </TBODY> </TABLE> </BODY> </HTML> from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/remote/http/common.rb:66:in `create_response' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/remote/http/default.rb:66:in `request' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/remote/http/common.rb:40:in `call' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/remote/bridge.rb:634:in `raw_execute' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/remote/bridge.rb:99:in `create_session' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/remote/bridge.rb:68:in `initialize' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/ie/bridge.rb:47:in `initialize' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/common/driver.rb:35:in `new' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r/common/driver.rb:35:in `for' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdrive r.rb:67:in `for' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.4/lib/watir-webdriver/brows er.rb:46:in `initialize' from (irb):4:in `new' from (irb):4 from C:/Ruby200-x64/bin/irb:12:in `<main>' irb(main):005:0>
在网上找到的解决办法:
由于在安装的时候在命令行中设置的代理,而在执行程序的时候没有去掉代理,导致错误。
如果在Windows环境下的话,重新开启一个CMD窗口就行了