gpt4 book ai didi

ruby - HTTP 请求路径为空 (ArgumentError)

转载 作者:太空宇宙 更新时间:2023-11-03 16:50:18 28 4
gpt4 key购买 nike

我是 ruby​​ 编程的新手。这是我在 Watir 的第一个程序。当我执行下面的代码时,我得到 HTTP 请求路径为空 (ArgumentError)。感谢您帮助修复此错误。我正在通过代理设置访问互联网。我在环境变量中添加了 HTTP_PROXY 变量到 http://myproxy.mynetwork.net:8008/

测试.rb

require "watir"
require "rubygems"
require "rspec"
require "watir-webdriver"

puts "Hello,World...!"

@browser = Watir::Browser.new
@browser.goto("http://www.google.com")
@browser.close
puts "Browser should have been closed.."

输出

d:\>ruby test.rb
Hello,World...!
C:/Ruby193/lib/ruby/1.9.1/net/http.rb:1860:in `initialize': HTTP request path is
empty (ArgumentError)
from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:2093:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:71:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:71:in `new_request_for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:35:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/default.rb:64:in `request'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/http/common.rb:40:in `call'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/bridge.rb:634:in `raw_execute'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/bridge.rb:99:in `create_session'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/remote/bridge.rb:68:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/firefox/bridge.rb:36:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/common/driver.rb:31:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver/common/driver.rb:31:in `for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.41.0/lib/s
elenium/webdriver.rb:67:in `for'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.9/lib/watir
-webdriver/browser.rb:46:in `initialize'
from test.rb:8:in `new'
from test.rb:8:in `<main>'

Firefox 浏览器窗口正在打开。之后地址栏没有变化,一段时间后它会关闭。

最佳答案

net/http 需要一个有效的路径。所以你必须在 URL 的末尾加上一个斜杠,像这样:

@browser.goto("http://www.google.com/")

关于ruby - HTTP 请求路径为空 (ArgumentError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23794376/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com