Sign in to follow this  
Followers 0
barkeeper

Javascript popup autoclick ok

18 posts in this topic

#1 ·  Posted (edited)

hi there,

I have a question to you guys, not sure if it's even possible, but want to ask anyway.

Is there an option in AutoIt to check for a javascript dialog popup and when it appears auto-click the OK button? We use a piece of online software at work that checks if you're still using it every 30 minutes, you click OK to make the dialog disapear and still be logged in, if you don't click within 10 minutes you get logged out.

I'd like the script to auto check for a webpage javascript dialog, and click OK when it appears. I'll include a screenshot to make things easier for you.

Thank you for looking into this and helping me, I appreciate it a lot!

JJ

- The Netherlands

post-56391-12674446320144_thumb.jpg

Edited by barkeeper

Share this post


Link to post
Share on other sites



Thanks! Could you give me a snippet of how that code would look like maybe ?

JJ

well you could check for it via a pixelchecksum() every nine minutes, and if its there then click it.

read

PixelChecksum()

Sleep()

MouseClick()

in the helpfile.

Unfortunately thats the only way I know.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Something like this, you will need to read the helpfile with regards the functions.

And you will need to use au3windowinfotoll to get some info.

$pChecksum = ;whatever the checksum of the popup is

While 1
Sleep(540000)
$pCheck = PixelChecksum() ;coordinates in here
If $pCheck = $pChecksum Then
MouseClick() ;coordinates in here
EndIf
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I would use WinGetPos since it looks like that popup is a set size. You can look for a window of that size in a loop then controlclick the ok.

$window=WinGetPos("Message from webpage")
While 1
    $window=WinGetPos("Message from webpage")
If $window[2]="enter the window width here" And $window[3]="enter the height here" Then
    ControlClick("Message from webpage","","control ID of the OK button here","Left",1);use the windowinfo tool from autoit
EndIf
Sleep(10)
WEnd

this little 2 line snipit will give you the width and height, but only run it when the window you want the size of is open

$window=WinGetPos("Message from webpage")
MsgBox(0,"Size of window","Size: Width: "&$window[2]&" Height: "&$window[3])

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

You guys Rock, I'm going to try that right away, will let you know the outcome.

Share this post


Link to post
Share on other sites

Yes that would probably be better.

I was under the impression javascript did not show up as a window, rather an object on the webpage.

I just tested it on our clock in page which uses a popup with the same window name and it worked fine. Not to say it will for this as I can't test it on that window. this is the exact code that worked for me (the window I'm sure is going to be a different size though)

$window=WinGetPos("Message from webpage")
While 1
    $window=WinGetPos("Message from webpage")
    If IsArray($window) Then
If $window[2]=185 And $window[3]=126 Then
    ControlClick("Message from webpage","","[CLASS:Button; INSTANCE:1]","Left",1);use the windowinfo tool from autoit
EndIf
EndIf
Sleep(10)
WEnd

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

My test is going to take a little time since I need to let the application get idle, if I get a support call in the meantime the timeout counter is reset :mellow:

As soon as I know more, I'll post it here.

JJ

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It worked :mellow: Thank you guys sooo much, the working code for me was :

$window=WinGetPos("Message from webpage")
While 1
    $window=WinGetPos("Message from webpage")
    If IsArray($window) Then
If $window[2]=377 And $window[3]=204 Then
    ControlClick("Message from webpage","","[CLASS:Button; INSTANCE:1]","Left",1);use the windowinfo tool from autoit
EndIf
EndIf
Sleep(10)
WEnd

1 more question : Will this LOOP and wait for the next time the popup appears ?

Edited by barkeeper

Share this post


Link to post
Share on other sites

1 more question : Will this LOOP and wait for the next time the popup appears ?

yes, While 1 is a neverending loop


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

Got it, such a newbie :mellow:

Thank you guys for the help! you're lifesavers :(

Share this post


Link to post
Share on other sites

1 thing i've noticed, not sure if you guys know any solution for that.

But it turns out that with Vista Aero turned on the popup appears to have a different size (the border gets slighly thicker).

Any ideas ?

Jj

Share this post


Link to post
Share on other sites

Is this window "message from webpage" the only one with that name ?

If so you dont need to check its size.

Yeah, he said Javascript popup so I wasn't sure if using the window title would work.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

It appears to have different sizes when you have "AERO" activated, it's like a little extra border is around the screens, adapting the size in the source did the trick.

post-56391-12676133844906_thumb.jpg

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