Jump to content
Sign in to follow this  
VAG

How to click on a IE pop up dialog

Recommended Posts

VAG

I have this _IE script which help me to filll in data in a Product Registration Wizard. At the end of the registration, the site will pop up a IE dialog window. I would like to perform a click on this dialog to continue. But I notice my script cannot continue until I manually clicking OK button on this dialog.

Can anyone point out what have I done wrong in the script? Thanks

PS:/Sorry about the $sLink line, the Forum Editior always help me to convert the URL to a link. How do I disable it?Posted Image

#include <IE.au3>

$sLink = [url="https://register.creative.com/register/welcome.asp"]https://register.creative.com/register/welcome.asp[/url]

$oIE = _IECreate ($sLink, 0, 1, 1, 1)
WinSetState(_IEPropertyGet($oIE, "hwnd"), "", @SW_MAXIMIZE)

; Register Your Product - Page 1
;-------------------------------

$oForm = _IEFormGetObjByName($oIE, 1)

$oRegion = _IEFormElementGetObjByName($oForm, "Region")      ;Region Selection
_IEFormElementSetValue($oRegion, 2)         ;Select "Asia"

$oCountry = _IEFormElementGetObjByName($oForm, "Country")   ;Country Selection
_IEFormElementSetValue($oCountry, 65)          ;Select "Singapore"

$oLanguage = _IEFormElementGetObjByName($oForm, "Language")     ;Language Selection
_IEFormElementSetValue($oLanguage, 1)          ;Select "English"

_IEFormImageClick ($oIE, "/register/images/btn_registernow_1.gif", "src") ;Register Now Button

_IELoadWait($oIE)


; Register Your Product - Page 2
;-------------------------------

$oForm = _IEFormGetObjByName($oIE, 1)  

_IEFormElementCheckBoxSelect($oForm, "0", "nRegAuto", 1, "byValue")   ;Standard Registtration

_IEFormImageClick ($oIE, "/register/images/btn_next_1.gif", "src")   ;Next >> Button

_IELoadWait($oIE)


; Register Your Product - Page 3
;-------------------------------

$oForm = _IEFormGetObjByName($oIE, 1)      

$oMainCategory = _IEFormElementGetObjByName($oForm, "MainCategory")   ;MainCategory
_IEFormElementSetValue($oMainCategory, 13)      ;Select "Accessories"

$oSubCategory = _IEFormElementGetObjByName($oForm, "SubCategory")   ;SubCategory
_IEFormElementSetValue($oSubCategory, 748)      ;Select "MP3 Players - Others"

$oProduct_ID = _IEFormElementGetObjByName($oForm, "Product_ID")    ;Product ID
_IEFormElementSetValue($oProduct_ID, "DUMMYPREFIX_PF1080|11660")   ;Select "Cradle and Belt Clip - ZEN Micro"

_IEImgClick ($oIE, "/register/images/btn_addproduct_1.gif", "src")   ;Add Product button
$oForm = _IEFormGetObjByName($oIE, 1)          ;Reinitial Form Obj due to update of form

$oSerialNumber = _IEFormElementGetObjByName ($oForm, "DUMMYPREFIX_PF1080") ;Serial Number
_IEFormElementSetValue ($oSerialNumber, "1234567890")

$oMonth2 = _IEFormElementGetObjByName ($oForm, "Month2")    ;Date od Purchase
_IEFormElementOptionselect ($oMonth2, 1, 1, "byValue")

$oyear2 = _IEFormElementGetObjByName ($oForm, "year2")      ;Date od Purchase
_IEFormElementOptionselect ($oyear2, 2010, 1, "byValue")

$oFirst_Name = _IEFormElementGetObjByName($oForm, "szFirstName")   ;First Name
_IEFormElementSetValue($oFirst_Name, "Peter") 

$oLast_Name = _IEFormElementGetObjByName($oForm, "szLastName")    ;Last Name
_IEFormElementSetValue($oLast_Name, "Yeung")

$oEmail = _IEFormElementGetObjByName($oForm, "szEmail")      ;Email  
_IEFormElementSetValue($oEmail, "[email="pyeung@ctl.creative.com"]pyeung@ctl.creative.com[/email]") 

$oCity = _IEFormElementGetObjByName($oForm, "szCity")      ;City
_IEFormElementSetValue($oCity, "Singapore") 

$oAddress = _IEFormElementGetObjByName($oForm, "szAddress")     ;Address
_IEFormElementSetValue($oAddress, "31 International Business Park") 

$oZip_Code = _IEFormElementGetObjByName($oForm, "szZip")    ;Zip/Postal Code: 
_IEFormElementSetValue($oZip_Code, "609921") 

_IEFormElementRadioSelect  ($oForm, 0, "szGender", 1, "byIndex")   ;Gender

$oDob_day = _IEFormElementGetObjByName ($oForm, "szDob_day")    ;Date of Birth:
_IEFormElementOptionselect ($oDob_day, 1, 1, "byValue")

$oDob_month = _IEFormElementGetObjByName ($oForm, "szDob_month")   ;Date of Birth:
_IEFormElementOptionselect ($oDob_month, 1, 1, "byValue")

$oDob_year = _IEFormElementGetObjByName ($oForm, "szDob_year")    ;Date of Birth:
_IEFormElementOptionselect ($oDob_year, 2000, 1, "byValue")

_IEFormElementCheckBoxSelect($oForm, "1", "nReceiveEmail", 0, "byValue") ;Keep me in the loop on the latest Creative products, special offers and events 

_IEFormImageClick ($oIE, "/register/images/btn_next_1.gif", "src")   ;Next >> Button

_IELoadWait($oIE)

; Register Your Product - Page 4
;-------------------------------

$tim = timerinit()
While 1
Sleep(1000)
If WinGetText("Windows Internet Explorer", "") = "Your product registration has been successful.Please close your existing browser to update your system information." Then
  ControlClick("Windows Internet Explorer", "", "Button1")
  MsgBox(0, "", "Registration Successful")
  sleep(5000)
  ExitLoop
EndIf 
If timerdiff($tim) > 10000 then 
    MsgBox(0, "", "Registration fail")
  exitloop
EndIf
WEnd

Share this post


Link to post
Share on other sites
omikron48

Look at ControlClick, and use Au3Info.exe (AutoIt v3 Window Info Tool) to get information on the popup and control you need clicked.

You might also want to look at WinWait to make the script wait until the popup window appears before it executes the ControlClick.

Edited by omikron48

Share this post


Link to post
Share on other sites
VAG

Thanks for the suggestion. But what I noticed is any line of code after this line will not run. Seems like the IE dialog has hanged the script. Only when I click on the dialog then the script continue to run. So putting any checking after this won't work...

_IEFormImageClick ($oIE, "/register/images/btn_next_1.gif", "src") ;Next >> Button

Share this post


Link to post
Share on other sites
VAG

Thanks for the info...I understand now that I need to use _IEAction( ,"focus") and ControlSend() to do it. Posted Image

But one thing I notice for the site I need to control, the alert is generated by a Javascript on a seperate page. There is no "Submit" Obj for me to reference to. So how do I use the _IEGetObjByName() to reference to this Javascript alert?

Here is part of the HTML code of the alert page:

<table width="759" align="center" cellpadding="5" cellspacing="0" border="0">
<tr>
<td align="left"><font color="#000160" size="2" class="textbluebold">


  



  
  <table align="center" width="640" cellpadding="5" cellspacing="0" border="0">
  <tr>
   <td colspan="2" valign="top"><FONT face=Verdana color=#2c54ff size=4>Thank you for completing your registration.<BR></FONT>We hope you enjoy using your Creative product(s).
   
<hr color="#eeeeee">

   Get the most from Creative with these additional resources
   <p>
   </td>
  </tr>
  <tr valign="top"> 
   <td><img src="/register/images/img1.jpg" width="70" height="70" alt="Creative How-Tos" align="absmiddle"></td>
   <td><font color="#2c54ff"><b>Creative How To</b></font>
    
Online tutorials that'll help you enjoy your Creative product to its fullest. (Currently available for Creative MP3 players, speakers, web cameras and Sound Blaster products.)</font>
   </td> 
  </tr>
  <tr valign="top">
   <td><img src="/register/images/img2.jpg" width="70" height="70" alt="Products" align="absmiddle"></td>
   <td><font color="#2c54ff"><b>Products</b></font>
    
The latest from Creative - learn more about them&nbsp;<A href="[url="http://www.creative.com/products/"]http://www.creative.com/products/">here.</A[/url]>
   </td> 
  </tr>
  <tr valign="top">
   <td><img src="/register/images/img3.jpg" width="70" height="70" alt="Customer support" align="absmiddle"></td>
   <td><font color="#2c54ff"><b>Customer support</b></font>
    
Access a comprehensive range of product support services, or send us your <A href="[url="http://sg.creative.com/contactus"]http://sg.creative.com/contactus">feedback[/url] and suggestions.</A>
   </td>
  </tr>
  </table> 


<script langauge="javascript" defer>
<!--
  try {
   alert('Your product registration has been successful.\nPlease close your existing browser to update your system information.')   
  }
  catch(e) {;;}
// --> 
</script>
</font>
</td>
</tr>
</table>
Edited by VAG

Share this post


Link to post
Share on other sites
jvanegmond

Thanks for the info...I understand now that I need to use _IEAction( ,"focus") and ControlSend() to do it. Posted Image

Actually, example 2 of _IEAction shows exactly how to close the alert window:

; Wait for Alert window, then click on OK
WinWait("Windows Internet Explorer", "ExampleFormSubmitted")
ControlClick("Windows Internet Explorer", "ExampleFormSubmitted", "[CLASS:Button; TEXT:OK; Instance:1;]")
_IELoadWait ($oIE)

http://sadtrombone.com/

Click it.

Share this post


Link to post
Share on other sites
VAG

Thanks for the reply. But then how may I put in the reference obj name for the "????" in _IEGetObjByName(). The alert box in the page is not triggered by a Submit button form element?

FYI: I have used AutoIT Info to scan the alert box, There is only Window Tiltle but no text. Tht's why I put it as WinWait("Windows Internet Explorer", "")

$oSubmit = _IEGetObjByName ($oIE, "????")
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction ($oSubmit, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

WinWait("Windows Internet Explorer", "")
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:1;]")
_IELoadWait ($oIE)

Share this post


Link to post
Share on other sites
jvanegmond

I thought you only needed to close the alert. Your script at the top seems quite complete..

You do realize that you only need part of example 2, right?

Share this post


Link to post
Share on other sites
VAG

I thought you only needed to close the alert. Your script at the top seems quite complete..

You do realize that you only need part of example 2, right?

Oh sorry, you mean part of the code in example 2, do u mean I can do like that:

I have tested it out. but not working...tht's why I need to use the entire code in example 2. Posted Image

<continue from original code...>

_IEFormImageClick ($oIE, "/register/images/btn_next_1.gif", "src")   ;Next >> Button

_IELoadWait($oIE)

; Register Your Product - Page 4
;-------------------------------

WinWait("Windows Internet Explorer", "")
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:1;]")
_IELoadWait ($oIE)

Share this post


Link to post
Share on other sites
SAG

Thanks for the suggestion. But what I noticed is any line of code after this line will not run. Seems like the IE dialog has hanged the script. Only when I click on the dialog then the script continue to run. So putting any checking after this won't work...

_IEFormImageClick ($oIE, "/register/images/btn_next_1.gif", "src") ;Next >> Button

I have found a similar thing. What I have found is that the _IEFormImageClick, by default, will wait for the page to load before continuing - reference the $f_wait = 1 (default) in the help. By changing this to '0', the script should continue without waiting for the page to load. Then you can get the pop up dialog with a WinActivate function and click a button on the window with a ControlClick.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.