Jump to content

ControlClick Help


Recommended Posts

Hi, All.

My purpose is to click a reset link and click the confirm box to finish the reset. I stuck in clicking the "OK" button after I clicked the reset link.

I have searched forum, unfortunately, I didn't find the similar issues. Is anyone can give me any suggestions? Thanks.

Html:

<a href="URL" onclick="return confirm('Do you wish to continue? The reset will take several minutes to complete!')">

Source Code:

...
WinWait("Windows Internet Explorer", "Do you wish to continue? The reset will take several minutes to complete!")
ControlClick("Windows Internet Explorer", "Do you wish to continue? The reset will take several minutes to complete!", "[CLASS:Button; TEXT:OK; Instance:1;]")
_IELoadWait ($oIE)

Is there anything wrong in argument of "ControlID"? How to fix this?

Edited by Avatar007
Link to comment
Share on other sites

The window Auto It Info tool doesnt give any Control information about the ok/cancel box (for me atleast).

So sending click to a control that seems to not exist wouldnt work.

I used this as my example...

<html>
 <head>
 </head>

 <body>
  <a href="http://www.google.com" onclick="return confirm('Do you wish to continue? The reset will take several minutes to complete!')">link</a>
 </body>

</html>

However i noticed that the "Ok" button as default is selected so just sending {space} might work.

like this..

$title = "Message from webpage"
WinWait($title)
ControlSend($title, "", "", "{space}")

EDIT: Ignore above

I made a mistake no idea how or why but anyway.

It seems ControlClick's first "Click" only highlights the "OK" button and you need to send another for it to actually "Click it".

Like this

$title = "Message from webpage"
WinWait($title)
ControlClick($title, "OK", "Button1", "Left", "2")

Works for me

Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

I appreciate your response. The confirm message is a pop-up window which in the attachment.

I test this code, It still does not work:

...$title = "Windows Internet Explorer"
WinWait($title)
ControlClick($title, "OK", "Button1", "Left", "2")

The original idea is from help of AutoIt:

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

The difference between my script and example is that the pop-up window is a alert windows.

Another problem is follow the ControlClick function "ControlClick ( "title", "text", controlID [, button [, clicks [, x [, y ]]]] )", it need controlID in this parameter which I can not find in my test. Anyone knows the setting of "controlID" in ControlClick function?

The window Auto It Info tool doesnt give any Control information about the ok/cancel box (for me atleast).

So sending click to a control that seems to not exist wouldnt work.

I used this as my example...

<html>
 <head>
 </head>

 <body>
  <a href="www.google.com" onclick="return confirm('Do you wish to continue? The reset will take several minutes to complete!')">link</a>
 </body>

</html>

However i noticed that the "Ok" button as default is selected so just sending {space} might work.

like this..

$title = "Message from webpage"
WinWait($title)
ControlSend($title, "", "", "{space}")

EDIT: Ignore above

I made a mistake no idea how or why but anyway.

It seems ControlClick's first "Click" only highlights the "OK" button and you need to send another for it to actually "Click it".

Like this

$title = "Message from webpage"
WinWait($title)
ControlClick($title, "OK", "Button1", "Left", "2")

Works for me

post-55700-12652008561134_thumb.jpg

Link to comment
Share on other sites

Thanks, Steveiwonder. I tested your html and script, It works fine. But it still not works in my script. My webpage is much more complicated, can you help me set the parameters in the controlclick function which can fix my issue? Html source:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" type="text/css" media="screen" href="/luci-static/ger/cascade.css" />
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" media="screen" href="/luci-static/ger/ie6.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="/luci-static/ger/ie7.css" /><![endif]-->
<script type="text/javascript" src="/luci-static/resources/VarType.js"></script>
<script type="text/javascript" src="/luci-static/resources/XHTML1.js"></script>
<script type="text/javascript" src="/luci-static/resources/Dropdowns.js"></script>
<title>BT OSIP EX - Reset Options</title>
</head>
<body class="lang_en">

<p class="skiplink">
<span id="skiplink1"><a href="#navigation">Skip to navigation</a></span>
<span id="skiplink2"><a href="#content">Skip to content</a></span>
</p>

......

<div id="maincontent">

<h2><a id="content" name="content">System</a></h2>
<h3>Reset System</h3><p>Resets the system with no changes to saved settings. This option will trigger a full reboot that will take several minutes to complete. When finished you will be returned to the log-in webpage.</p><p><a href="/cgi-bin/luci/;stok=E658F649A97ACABBF66DED769C968AB0/engineer/advanced/diagnostics/reboot?reboot" onclick="return confirm('Do you wish to continue? The reset will take several minutes to complete!')">Perform reset</a></p><h3>Reset system to factory defaults</h3>
<p>This option will restore all settings to the factory defaults and a full reboot of the system that will several minutes to complete. When finished you will be returned to the log-in webpage.</p><p><a href="/cgi-bin/luci/;stok=E658F649A97ACABBF66DED769C968AB0/engineer/advanced/diagnostics/reboot?restore" onclick="return confirm('Do you wish to continue? All current settings will return to factory defaults!')">Perform Reset to Factory Defaults</a></p><div class="clear"></div>
</div>

</body>
</html>

My webpage have a session management, the above code is in the redirection page after I login. I found a difference that every time I run my script, it stuck in the pop-up windows, but test your code, A prompt for ActiveX controls shows up. All tests are based on IE7. Why?

Test my code with the HTML i have also provided it works just fine for me. The attachment you showed me there is exactly the same one as i see with my HTML except the title

Edited by Avatar007
Link to comment
Share on other sites

I am quite sure this issue is occured in title of the popup windows, I have tried the title with "Microsoft Internet Explorer" and "Windows Internet Explorer", but failed. How to watch the title in the popup windows? I use IE7 in Windows XP.

I dont know where your going wrong, i used your HTML ... Ran my code and it works fine.

Obviously you need to ammend the $wintitle if its different on your machine as mine is "Message from webpage".

Link to comment
Share on other sites

Thanks again, Steveiwonder. I have confirmed the title is "Windows Internet Explorer" used AutoIt Window Info tool. I thought the difference between your webpage and mine is that mine uses javascript, but yours is only normal popup windows, I don't know further about this.

I also found a similar issue in this forum:Javascript popup issue

Though I used "clear link onclick event" method to resolve this issue, I still confused on the ControlClick dose not work in javascript popups. Neither I test as

WinWait("Microsoft Internet Explorer")
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:2;]")
nor
WinWait("Microsoft Internet Explorer")
ControlClick("Windows Internet Explorer", "", "[CLASS:Button; TEXT:OK; Instance:2;]")
, it seems lick stuck in the WinWait function.

Update: I just notice that the changes: Return handle on WinWait()

Description:Pauses execution of the script until the requested window exists.

Edited by Avatar007
Link to comment
Share on other sites

If your really stuggling, you can always use a MouseClick() instead :D or..

WinWait("Microsoft Internet Explorer")
ControlSend("Windows Internet Explorer", "", "", "{enter}")

Confirm() is javascript - it works fine on my computer - Sorry i can't help any further.

Maybe one of the Guru's on this forum might help out, you never know.

Edited by Steveiwonder

They call me MrRegExpMan

Link to comment
Share on other sites

I have fix my issue use

...
 $o_link =_IELinkGetCollection ( $oIE, 53)  
 $o_link.onclick=""
 $o_link.click
...

I just wonder why I can not use controlclick in my test. Dose anybody have the same issue use winwait & controlclick?

Anyway, thanks a lot for all your attention. I will move on to another script.

Link to comment
Share on other sites

  • 1 month later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...