【发布时间】:2016-02-05 22:01:32
【问题描述】:
我正在尝试使用 watir/watir-webdriver 测试在网页上上传图片/文档,但我尝试的所有方法都不起作用。
例如在Imgur上上传图片:
require 'watir'
require 'watir-webdriver'
require 'rspec'
describe "Upload test" do
before(:all) do
@browser = Watir::Browser.new :firefox
@browser.goto("https://imgur.com/")
end
context "Upload test" do
it "can upload picture" do
@browser.link(:text, "upload images").click
@browser.file_field(:name, "img_path").set("img_path")
@browser.button(:value,"Save").click
end
end
after(:all) do
@browser.close unless debugging?
end
end
有一个错误。
Failures:
1) Upload test Upload test can upload picture
Failure/Error: @browser.link(:text, "upload images").click
Watir::Exception::UnknownObjectException:
unable to locate element, using {:text=>"upload images", :tag_name=>"a"}
# /var/lib/gems/1.9.1/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:536:in `assert_element_found'
# /var/lib/gems/1.9.1/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:508:in `assert_exists'
# /var/lib/gems/1.9.1/gems/watir-webdriver-0.9.1/lib/watir-webdriver/elements/element.rb:114:in `click'
# ./PROBA.rb:14:in `block (3 levels) in <top (required)>'
Finished in 11.47 seconds (files took 0.19261 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./PROBA.rb:13 # Upload test Upload test can upload picture
我曾尝试将其上传到其他网站,但我不能。任何人都可以告诉我使用 watir 上传文件的正确方法吗?我认为使用“flash”按钮有一些技巧,但我不确定?
【问题讨论】:
-
会发生什么?如果抛出错误,请包含堆栈跟踪。此外,链接到
file_field方法的set方法将目录路径(到图像)作为参数。 -
我现在已经包含了错误堆栈跟踪..
-
没有“上传图片”文字的链接。有一个跨度,虽然:
<span class="upload-btn-text">upload images</span>和一个带有初始大写文本的链接:<a class="creation-dropdown-upload" href="javascript:;">Upload Images</a>
标签: ruby rspec watir watir-webdriver