我正在尝试使用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上传文件的正确方法吗?我认为使用“闪光”按钮有一些技巧,但我不确定?
答案 0 :(得分:0)
该错误表明它没有看到与文字的链接&#34;上传图片&#34;在页面上,与文件上传无关。
话虽如此,如果文本字段已经可见,您应该这样做:
@browser.file_field(name: 'img_path').set @file_path
答案 1 :(得分:0)
您需要确保定位器准确无误。在您的示例中,您的目标是不存在的文字(即,没有链接文字&#34;上传图片&#34;)。
Dim actionsArr = New MyAction() {action1, action2, action3, action4}