How to upload a file with watir and IE?

前端 未结 5 1356
情歌与酒
情歌与酒 2020-12-18 01:07

I am writing a watir script to test an upload form.

But the script does not automatically choose the file that is to be uploaded from my harddrive.

Instead I

5条回答
  •  温柔的废话
    2020-12-18 02:06

      @modal = @browser.driver.switch_to.alert   #Switch to open windows modal
      key_to_send = "C:\\Users\\singhku\\Calabash_doc.pdf"  #Path and name of file
      @modal.send_keys(key_to_send)
    
      require 'win32ole'
      wsh = WIN32OLE.new('Wscript.Shell')
      wsh.AppActivate('Choose File to Upload')  #Name of the modal that is open
      wsh.SendKeys('{ENTER}')
    

提交回复
热议问题