我遇到的问题是我在方法上调用click_no_wait方法 控件显示“文件下载”框。它适用于 第一次。我使用Auto It来处理文件下载框并保存 文件在特定位置。现在,当我尝试使用时 click_no_wait在同一控件上,它不会显示文件下载 框,但如果我在调用click_no_wait之前刷新浏览器,它 将显示“文件下载”框。所以,我的问题是它是 自动它没有被释放的情况因此click_no_wait不能 找到控件或实现有什么问题 click_no_wait方法。
环境: 操作系统:Microsoft XP SP2 Ruby:ruby 1.8.6 patchelevel 398 Watir:1.8.1
以下是我使用控件的方式
def click_export_button
control = browser.button(:id,'export-button')
$DEBUG = true
#browser.refresh #- If this line is not commented, the dialog appears
control.click_no_wait #-- I replace click_no_wait with click and/or click! and the code freezes, so the control is found
download_file("C:\\test.csv")
$DEBUG = false
end
以下是下载文件的代码
def download_file(filePath = nil)
autoIt = WIN32OLE.new("AutoItX3.Control")
timeout = 10
fileDownloadWindowTitle = "File Download"
handle = autoIt.WinWait(fileDownloadWindowTitle, "Do you want to open or save this file?", timeout)
retVal = nil
unless (handle.eql? @autoItError)
autoIt.WinActivate(fileDownloadWindowTitle)
autoIt.ControlClick(fileDownloadWindowTitle, "", "&Save")
saveWindowTitle = "Save As"
windowHandle = autoIt.WinWaitActive(saveWindowTitle, "", timeout)
if (windowHandle == 1)
retVal = save_file(saveWindowTitle, autoIt, filePath) #-- function to save the file to the location
end
else
puts "Unable to download the file"
end
autoIt.ole_free
return retVal
end
这是我得到的错误
ruby -e "$:.unshift('c:/ruby/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/
watir/win32ole').unshift('c:/ruby/lib/ruby/gems/1.8/gems/
commonwatir-1.8.1/lib').unshift('c:/ruby/lib/ruby/gems/1.8/gems/
firewatir-1.8.1/lib').unshift('c:/ruby/lib/ruby/gems/1.8/gems/
watir-1.8.1/lib');require 'c:/ruby/lib/ruby/gems/1.8/gems/watir-1.8.1/
lib/watir/core';Watir::Button.new(Watir::IE.attach(:hwnd,
6751822), :unique_number, 3).click!();"
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/element.rb:58:in
`assert_exists': Unable to locate element, using :unique_number, 3
(Watir::Exception::UnknownObjectException)
from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.8.1/lib/watir/
element.rb:275:in `click!'
from -e:1
任何帮助将不胜感激。 提前致谢
答案 0 :(得分:0)
您可以尝试在click_no_wait之前添加以下内容:
"browser.refresh"