In Firewatir, how can I interact with the Firefox print dialog?

I am trying to check a page with a print dialog immediately after accessing it. All I have to do is close the dialog box or click β€œCancel” so that I can interact with the page behind it. I tried to figure out how to do this, but everything I found indicates that this is not possible in Firefox.

+4
source share
1 answer

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:

  • Run elevated cmd.exe

  • regsvr32 C: \ Ruby187 \ lib \ ruby ​​\ gems \ 1.8 \ gems \ watir-1.6.5 \ lib \ watir \ AutoItX3.dll

(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).

+2
source

Source: https://habr.com/ru/post/1341718/


All Articles