Sign in to follow this  
Followers 0
MaritimeGirl

Anonymous Javascript Alert OK Button Press?

16 posts in this topic

I have gone through so many pages of suggestions but none seem to work for me.

I have a page which triggers an alert but has no name for the alert. It's just the default "Windows Internet Explorer" window title and my statement of "Cannot exceed 500 characters." and an OK button. No, I cannot change the application code to give it a title.

Of course my script grinds to a screeching halt when it gets to that alert since I can't get access to it to click the OK button. ControlClick needs a window title so I don't think I can get that to work or maybe I haven't tried the right configuration. MouseClick does not run until after I manually press the OK button and my script will then resume. I'd rather not hardcode coordinates for the mouseclick if I can programmatically access that pesky little OK button to click it.

Does anyone have a way to fix this?

Share this post


Link to post
Share on other sites



Hi, MaritimeGirl. Is there any text in the field you can grab, if not the title? I've used something similar to this in the past:

If WinExists("", "Test") Then
WinClose("", "Test")
EndIf

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Yes, I have the text of the alert.

It looks good but the problem remains that how do I get it to be running so that the alert can be dismissed? As soon as the alert happens (which I trigger (by populating an IE textarea with too much text on purpose as a test), the script stops completely so that code would not be executed. I saw an example using AdlibEnable that looked promising but that function was discontinued in a previous version of AutoIt.

I know I would need to have a timed loop of your 3 lines of code already running before the alert happens. How?

Share this post


Link to post
Share on other sites

MaritimeGirl,

AdlibEnable/Disable were not discontunued, they were superceded by AdlibRegister/Unregister which allow several Adlib functions to be set at the same time. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Something like this might get you started.

AdlibRegister("Popup")

Func Popup()
    If WinActive("", "Test") Then
       WinClose("", "Test")
    EndIf
EndFunc

Edit: Beaten to the punch again :)

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I was hopeful but no such luck.

I tried AdlibRegister and the function does not get called until after I manually press the OK button on the alert.

Here's the bare bones relevant code that I tried:

...

$o_form = _IEFormGetCollection ($oIE, 0)

$o_name = _IEFormElementGetObjByName($o_form, "myTextArea")

AdlibRegister("Popup")

_IEFormElementSetValue($o_name, "way more than 500 characters...")

AdlibUnRegister()

...

Func Popup()

msgbox(0,"was called","was called to kill popup")

If WinActive("", "Cannot exceed 500 characters.") Then

WinClose("", "Cannot exceed 500 characters.")

EndIf

EndFunc

...

When I run that, I get my popup, I manually press OK and THEN I'm greeted by the msg from the Popup function.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

MaritimeGirl, notice from the Help file...

";... execution must be non blocking, avoid ...Wait(), MsgBox(), InputBox() functions"

Have you tried it without the MsgBox?

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Tried without the msg as well - doesn't kill the popup either.

Share this post


Link to post
Share on other sites

Hi, MariTimeGirl. It may be more helpful if you post your script in full. I duplicated the piece you gave me, using another site to enter the text, and the Popup function successfully closed the popup for me.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I can't post the website nor the 2500 lines of code as it is a confidential intranet application.

I have made a brand new test html and au3 to illustrate the problem.

Here is the alert.html...

<html>

<body>

<form>

<textarea id="mytextarea" name="mytextarea" onfocus="javascript:alert('too much text')""

onchange="javascript:alert('too much text')"

onkeypress="javascript:alert('too much text')"></textarea>

</form>

</body>

</html>

Here is the alert.au3...

#include "IE.au3"

Dim $oIE

_IEAttach ($oIE)

If Not IsObj($oIE) Then

$oIE = _IECreate ()

_IENavigate ($oIE, "http://localhost/alert.html")

EndIf

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

WinSetState($HWND, "", @SW_MAXIMIZE)

$o_form = _IEFormGetCollection ($oIE, 0)

$o_name = _IEFormElementGetObjByName($o_form, "mytextarea")

_IELoadWait($oIE, 5000)

AdlibRegister("Popup")

_IEFormElementSetValue($o_name, "x")

AdlibUnRegister()

msgbox(0,"","After popup manually pressed")

Func Popup()

If WinActive("", "too much text") Then

WinClose("", "too much text")

EndIf

EndFunc

Share this post


Link to post
Share on other sites

So I've stumped everyone with this? :)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

mmm i don't think you understnad how the popup function works. I've intercepted many message boxes without any issue.

Your adlibregister must be called first. Then make a loop.

If the window appears, it will be closed.

Try to get the window info with au3info.exe

in the popup function :

Func Popup()
consolewrite ("window is trapped !")
If WinActive("", "too much text") Then
WinClose("", "too much text")
EndIf
EndFunc

It doesn't matter if the popup has been clicked or not

for the adlib, please use different value, more 500ms than default.

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

According to documention, AdlibRegister constantly calls the function until AdlibUnregister is called at the given interval. I've added the time parameter as 750. It still doesn't dismiss the popup. Based on your post, I can't determine what you're telling me to loop. I tried looping a call to Popup() and my alert trigger instide the adlib commands but it still doesn't work. And the title is as I mentioned in my first post - the default of "Windows Internet Explorer" which I've also tried specifying in the Popup() function.

If you can get that snippet of example code to work, please show me the exact syntax. I've spent days trying to get this to work and no matter what I've tried, I've been forced to manually press the OK button.

Edited by MaritimeGirl

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