Hi Wesley,

iewin.clickprompt() will click the button in the popup and return the
popup text.

This is the definition - def clickprompt(but="OK",txt ="", waitTime =
10)
iewin.clickprompt("CANCEL")  # will click cancel button.. actually if
you pass in anything other than OK, cancel will be clicked.
iewin.clickprompt("OK") or iewin.clickprompt() will click the ok
button.
iewin.clickprompt("OK", "input text")  #can be used to pass in values
into the prompt box.

iewin.clickprompt("OK", "", 20) #can increase the wait time for the
popup to occur. time = 20*0.2
will return '' if there is no popup.

Code is present here - http://pastie.org/595060
Pasting it here also -
################################################
    def clickprompt(but="OK",txt ="", waitTime = 10)
      tim = 0
      poptxt= ''
      while tim < waitTime
        sleep 0.2
        pophwnd = Win32API.new("user32", "GetWindow", 'Li', 'L').Call
(@ie.hwnd.to_i, 6)
        # the above returns any popup  windows that are present for
the specific window
        tim += 0.2
        tim += waitTime if pophwnd != 0
      end
      return '' if pophwnd == 0
      button = but.upcase
      outval = ' ' * 30
      Win32API.new("user32", "GetWindowText", 'Lpi', 'L').Call
(pophwnd,outval,30)
      popwndtitle = outval.rstrip.chomp("\000") # window title stored
here
      outval = nil
      #poptype = 0
      #alert and confirm have ie6 - Microsoft Internet Explorer
      #ie7 - Windows Internet Explorer
      #ie8 - Message from  webpage
      if popwndtitle.include?("Microsoft Internet Explorer") ||
        popwndtitle.include?("Windows Internet Explorer") ||
        popwndtitle.include?("Message from webpage")
        #confirm and alerts have the above 3 window titles
        # poptype =1 means this is a javascript alert tag
        #poptype = 1
        poptxt = handlepopup1(pophwnd,button)
      elsif popwndtitle.include?("Explorer User Prompt")
        #prompts have the above window title
        #poptype = 2
        poptxt = handlepopup2(pophwnd,button, txt)
      elsif popwndtitle.include?("Connect to")
        #authentication dialog
        #also make sure the username and password text fields are
present - if present we got the auth dialog
        cntrlhwnd = 0
        cntrlhwnd = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 1002)
        #poptype = 3 if cntrlhwnd != 0 #verified the 2 textboxes are
present to enter the values
        return '' if cntrlhwnd  == 0
        poptxt = handlepopup3(pophwnd,button, prompt)
      end
      return poptxt
    end

  def handlepopup1(pophwnd, button)
    # handles the alerts and confirm dialogs
    #Yes there is a popupwindow... hence get the controlhandle for the
text control - 65535
    cntrlhwnd = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call
(pophwnd, 65535)
    #now get the text from the popup
    outval = ' ' * 900
    Win32API.new("user32", "GetWindowText", 'Lpi', 'L').Call
(cntrlhwnd,outval, 900)
    poptext = outval.rstrip.chomp("\000")
    outval = nil

    #confirm ok-1 and cancel-2, alert ok-2
    cntrlhwndOK = 0
    cntrlhwndCANCEL = 0
    cntrlhwndOK = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call
(pophwnd, 1)
    if cntrlhwndOK == 0 # only 1 button alert
      cntrlhwndOK = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 2)
      clickWin32Button(cntrlhwndOK) # done clicking javascript ok
button
      return poptext
    else # this is a confirm with 2 buttons
      cntrlhwndCANCEL = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 2)
    end
    button.include?("OK") ? clickWin32Button(cntrlhwndOK) :
clickWin32Button(cntrlhwndCANCEL)
    #clickWin32Button(cntrlhwndCANCEL)
    return poptext
  end
  private :handlepopup1

  def handlepopup2(pophwnd, button, prompt)
    #handles prompt boxes which takes a value as input
    cntrlhwndOK = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call
(pophwnd, 1)
    cntrlhwndCANCEL = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 2)

    # get handle to the text control from the prompt box
    cntrlpromptText = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 8132)
    #now get the text from the popup
    outval = ' ' * 200
    Win32API.new("user32", "GetWindowText", 'Lpi', 'L').Call
(cntrlpromptText,outval, 200)
    poptext = outval.rstrip.chomp("\000")
    outval = nil

    cntrltextarea = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 8133)
    if prompt.size != 0
      sendmessage = Win32API.new("user32", "SendMessage", 'LLpp', 'L')
      sendmessage.Call(cntrltextarea, 0x000C, '', prompt) # calling
sendmessage with WM_SETTEXT
    end
    button.include?("OK") ? clickWin32Button(cntrlhwndOK) :
clickWin32Button(cntrlhwndCANCEL)
    return poptext
  end
  private :handlepopup2

  def handlepopup3(pophwnd, button, prompt)
    # handles the auth dialog box , 3 tries then the 401 page is shown
    cntrlhwnd = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call
(pophwnd, 1002)
    cntrlusername = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(cntrlhwnd, 1003)
    cntrlpassword = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(cntrlhwnd, 1005)
    if prompt.size == 2
      sendmessage = Win32API.new("user32", "SendMessage", 'LLpp', 'L')
      sendmessage.Call(cntrlusername, 0x000C, '', prompt[0]) # calling
sendmessage with WM_SETTEXT
      sendmessage.Call(cntrlpassword, 0x000C, '', prompt[1]) # calling
sendmessage with WM_SETTEXT
    end
    cntrlhwndOK = Win32API.new("user32", "GetDlgItem", 'Li', 'L').Call
(pophwnd, 1)
    cntrlhwndCANCEL = Win32API.new("user32", "GetDlgItem", 'Li',
'L').Call(pophwnd, 2)
    button.include?("OK") ? clickWin32Button(cntrlhwndOK) :
clickWin32Button(cntrlhwndCANCEL)

  end
  private :handlepopup3

  def clickWin32Button(cntrlhwnd)
    Win32API.new("user32", "SendMessage",'LLLL','L').Call(cntrlhwnd,
0x0006, 1,0)
    Win32API.new("user32", "SendMessage",'LLLL','L').Call(cntrlhwnd,
0x00F5, 0,0)
  end
  private :clickWin32Button

###################################

Thanks,
Tony
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to