Sign in to follow this  
Followers 0
LAGuy

Asp.Net Page - Click Image with javascript Alert Box

2 posts in this topic

Hi,

New to AutoIT and hoping I can master it enough to do some time saving work ! :mellow:

I'm trying to figure out how to Click the OK button on a Javascript Alert box that pops up

when I hit a Delete Icon Image on the Web Page.

I can successfully find and click on the Image but I can't seem to find the code to

click on the OK button in the Alert Box.

; Click on the Delete Icon Image to delete a record

_IEFormImageClick ($oIE, "./delete.gif", "src")

If @error Then

MsgBox(4096,"","Record Not Found" )

Else

; OK, so far - A Javascript Alert Box opens

; Windows Internet Explorer - Are you sure you want to delete this item ?

; THIS CODE DOES NOT WORK BELOW

$alerttext = "Are You Sure You Wish To Delete This Item?"

WinWaitActive("Windows Internet Explorer", $alerttext,3)

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

EndIf

The Image button HTML Looks like this:

<input type="image" name="dnn$ctr359$Users$grdUsers$ctl02$ctl02" title="Delete" src="/testwebsite/images/delete.gif" onclick="java script:return confirm('Are You Sure You Wish To Delete This Item?');" style="border-width:0px;" />

I'm not sure I can use the code below because the name= value can change on the Web Form

This code finds the Submit button on the page , I have some Edit / Delete Images on the page to click.

The AutoIT help for _IEAction

; *******************************************************

; Example 2 - Same as Example 1, except instead of using click, give the element focus

; and then use ControlSend to send Enter. Use this technique when the

; browser-side scripting associated with a click action prevents control

; from being automatically returned to your code.

; *******************************************************

;

#include <IE.au3>

$oIE = _IE_Example ("form")

$oSubmit = _IEGetObjByName ($oIE, "submitExample")

$hwnd = _IEPropertyGet($oIE, "hwnd")

_IEAction ($oSubmit, "focus")

ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

; 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)

Thanks, LA Guy

Share this post


Link to post
Share on other sites



Solved !

Ok, I get the Javascript Alert Box to close IF I follow the help on _IEAction to the letter.

I had to use the "name" of the Image Icon to get this working.

Although in Asp.Net this name will change if controls are added to the page ....

here's my code:

$oForm = _IEFormGetObjByName ($oIE, "Form")

;OK if I search by the Image control name !

$oSubmit = _IEGetObjByName ($oIE, "dnn$ctr359$Users$grdUsers$ctl02$ctl02") ; LONG GENERATED NAME by Asp.Net

$hwnd = _IEPropertyGet($oIE, "hwnd")

_IEAction ($oSubmit, "focus")

ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

$alerttext = "Are You Sure You Wish To Delete This Item?"

WinWaitActive("Windows Internet Explorer", $alerttext,3)

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

Thx, LA Guy

Hi,

New to AutoIT and hoping I can master it enough to do some time saving work ! :mellow:

I'm trying to figure out how to Click the OK button on a Javascript Alert box that pops up

when I hit a Delete Icon Image on the Web Page.

I can successfully find and click on the Image but I can't seem to find the code to

click on the OK button in the Alert Box.

; Click on the Delete Icon Image to delete a record

_IEFormImageClick ($oIE, "./delete.gif", "src")

If @error Then

MsgBox(4096,"","Record Not Found" )

Else

; OK, so far - A Javascript Alert Box opens

; Windows Internet Explorer - Are you sure you want to delete this item ?

; THIS CODE DOES NOT WORK BELOW

$alerttext = "Are You Sure You Wish To Delete This Item?"

WinWaitActive("Windows Internet Explorer", $alerttext,3)

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

EndIf

The Image button HTML Looks like this:

<input type="image" name="dnn$ctr359$Users$grdUsers$ctl02$ctl02" title="Delete" src="/testwebsite/images/delete.gif" onclick="java script:return confirm('Are You Sure You Wish To Delete This Item?');" style="border-width:0px;" />

I'm not sure I can use the code below because the name= value can change on the Web Form

This code finds the Submit button on the page , I have some Edit / Delete Images on the page to click.

The AutoIT help for _IEAction

; *******************************************************

; Example 2 - Same as Example 1, except instead of using click, give the element focus

; and then use ControlSend to send Enter. Use this technique when the

; browser-side scripting associated with a click action prevents control

; from being automatically returned to your code.

; *******************************************************

;

#include <IE.au3>

$oIE = _IE_Example ("form")

$oSubmit = _IEGetObjByName ($oIE, "submitExample")

$hwnd = _IEPropertyGet($oIE, "hwnd")

_IEAction ($oSubmit, "focus")

ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

; 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)

Thanks, LA Guy

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  
Followers 0