Aug
21
2008
0

Q. How do I get the text displayed in a javascript popup?

A. Use the WIN32OLE extension library with the autoit function library …
You will need to install autoit. You can download it here, once installed you can call the function library using the win32OLE extension library.
Example html:

<html>
   <head>
   <script language="javascript">
      function msgbox (textstring) {
      alert (textstring) }
   </script>
   </head>
   <body id="test_00test_0107" onload="">
      <form>
         <input name="text1" type=text>
         <input name="submit" type=button value="show me" onclick="msgbox(form.text1.value)">
     </form>
  </body>
</html>

Example watir:

require 'watir'
require 'rubygems'
require 'win32ole'
autoit = WIN32OLE.new('AutoItX3.Control') 
@b.goto('http://justaddwatir.com/watir/test_html/tc_0101_0200/test_0107.html')
@b.text_field(:name,"text1").set("This is the text in the popup")
@b.button(:name,"submit").click_no_wait
autoit.WinWaitActive("[Class:#32770]")
text = autoit.ControlGetText("[Class:#32770]", "", "Static2")
autoit.ControlClick("[Class:#32770]","","Button1")
puts text

In order for the autoit function to execute, you need to use the .click_no_wait method in watir before the autoit function. This is because once the pop up is presented, the focus comes off the IE window and the script will pause. The .click_no_wait tells the script to continue running regardless of what happens next.
You may use the autoit window identifier to get the properties of the pop up the static text.

Written by Sameh Abdelhamid in: watir | Tags: , , ,

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes