自动化系统级打印对话框

时间:2015-05-15 10:42:59

标签: ruby selenium autoit

我正在编写一个脚本来自动从网页上保存为流程。

基本上有一个网站上有一个名为PREVIEW的按钮。步骤将是:

  1. 点击预览按钮,按下显示包含所有数据的网页,在底部有一个PRINT按钮。
  2. 现在点击“打印”按钮,然后在Mozilla Firefox中显示“打印”对话框。
  3. 之后,从Name中选择PDF(即在Print对话框中下拉),然后单击OK按钮。
  4. 现在出现一个SAVE AS对话框,我需要提供保存文件和文件名的路径。
  5. CODE

    require 'selenium-webdriver'
    require 'win32ole'
    require "au3"
    require 'rautomation'
    
    driver = Selenium::WebDriver.for:firefox
    driver.manage().window().maximize();
    driver.navigate.to 'C:\Users\js830363\Documents\Userdata\GOI\New_Sahi\Ruby_Final\Demo2.html'
    wait = Selenium::WebDriver::Wait.new(:timeout =>180)
    
    wait.until {driver.find_element(:id,'Button1').click} #ID OF Print Button to click
    //Till Here it work fine.I get a print dialog box in firefox after that I have tried with
    
    Autoit:
    #Wait for the window to exist
    AutoItX3::Window.wait("Print") #The start of the title is enough to find it
    
    window = AutoItX3::Window.new("Print")#Get a reference to it
    
    window.activate #Bring it to the front
    AutoItX3::window.controlClick("Print", "", "1057")#id of OK and Cancel Button
    window.controlClick("Print", "", "1058")
    
    Rautomation:
    win = RAutomation::Window.new :title => /Opening rautomation/, :adapter => :ms_uia
    win.send_keys :enter
    
    file_dialog = RAutomation::Window.new :title => /Enter name of file/
    file_dialog.button(:value => "&Save").click
    

    错误

    C:\Users\js830363\Desktop>ruby test1.rb
    C:/Ruby200/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in
    rbuf_fill': Net::Rea dTimeout (Net::ReadTimeout)
             from C:/Ruby200/lib/ruby/2.0.0/net/protocol.rb:152:in `rbuf_fill'
             from C:/Ruby200/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
             from C:/Ruby200/lib/ruby/2.0.0/net/protocol.rb:144:in `readline'
             from C:/Ruby200/lib/ruby/2.0.0/net/http/response.rb:39:in `read_status_line'
    

    我正在使用ruby 2.0.0和Selenium Webdriver以及AutorIt我也尝试过使用reautomation但是无法点击打印按钮。

0 个答案:

没有答案