If you are on MacOS or Linux, donβt know what to tell you ... I bet this is possible, but I need to find out how myself. :)
If you are running Windows, I have some suggestions. I suggest checking the RAutomation gem, which is suitable for such tasks (search and click Cancel in the "Firefox Print" dialog box):
https://github.com/jarmo/RAutomation
Or you can try using AutoIt. Installing Watir also installs a copy of the AutoItX3.dll file, which you can use to easily automate your GUI like this.
To make sure AutoIt is ready for use on your system, try this in irb - this code will wait 10 seconds until the Firefox Print dialog box appears, then click the "Cancel" button:
irb(main):001:0> require 'win32ole' => true irb(main):002:0> autoit = WIN32OLE.new('AutoItX3.Control') => #<WIN32OLE:0x3c61ce0> irb(main):003:0> result = autoit.WinWaitActive('Print', '', 10) => 1 irb(main):004:0> result = autoit.ControlClick('Print', '', 'Cancel') => 1
If the WIN32OLE.new line ('AutoItX3.Control') throws an exception, you may need to use regsvr32.exe to register the DLL. For example, here's how to do it on Win7:
(Note that you may need to change the path above if your Ruby installation is not in C: \ Ruby187 or if you have a different version of Watir than 1.6.5.)
AutoIt documentation is here:
http://www.autoitscript.com/autoit3/docs/
The last thing to consider:
If the instruction in your code that invokes the Print dialog boxes until the dialog is closed, things will be a little more complicated. You will need to use threads or an external process to handle the dialog (since I do not think that FireWatir still has a click_no_wait method).