Jump to content

Help with clicking a button in popup window!


Gui
 Share

Recommended Posts

Aye guys, how would you click a button like in a popup window? Like in my bot when it clicks 'download the file' on the webpage, that popup window shows and says 'save, run, and some other thing'. I want to click 'save, but I don't know how. Ofcoarse I could use mouse click, but the coords would be different for different computers and such. I can't pixel search and click the pixel because all 3 buttons are the same pixels.. I tried Sending ("!s") for the shortcut to save, but that didn't work either. :) If you have any ideas, please help and post! Thanks. By the way I tried just sending ("s"), still didn't work. Aswell as Tab and Enter, no luck.

Gui.

Link to comment
Share on other sites

Aye guys, how would you click a button like in a popup window? Like in my bot when it clicks 'download the file' on the webpage, that popup window shows and says 'save, run, and some other thing'. I want to click 'save, but I don't know how. Ofcoarse I could use mouse click, but the coords would be different for different computers and such. I can't pixel search and click the pixel because all 3 buttons are the same pixels.. I tried Sending ("!s") for the shortcut to save, but that didn't work either. :) If you have any ideas, please help and post! Thanks. By the way I tried just sending ("s"), still didn't work. Aswell as Tab and Enter, no luck.

Gui.

hi

not sure what you wanna do here, but if you're trying to download a file from the internet, look into InetGet function.

Link to comment
Share on other sites

Look at WinWaitActive(). What output does the Info Tool give?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Use the Autoit Window tool to get the pop info and the button instance you want then do this:

If WinExists ("your pop up info") Then
   ControlSend("your pop up info", "", "[CLASS:Button; INSTANCE:2]",  "{ENTER}")
EndIf

Didn't work :)

_IENavigate($oIE,$url)
    $oForm = _IEFormGetCollection($oIE,1)
    $oButton = _IEFormElementGetCollection($oForm,0)
        _IEAction($oButton,'click') 
    Sleep(2000)
        If WinExists("File Download - Security Warning") Then
            ControlSend("File Download - Security Warning","Do you want to run or save","[CLASS:Button; INSTANCE:2]", "{ENTER}")
        EndIf
Link to comment
Share on other sites

please post the output from Autoit Window tool.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Oh sorry I'm retarded. Will do.

>>>> Window <<<<

Title: File Download - Security Warning

Class: #32770

Position: 310, 231

Size: 404, 266

Style: 0x94C80AC4

ExStyle: 0x00010101

Handle: 0x003508F4

>>>> Control <<<<

Class: Button

Instance: 2

ClassnameNN: Button2

Advanced (Class): [CLASS:Button; INSTANCE:2]

ID: 4427

Text: &Save

Position: 216, 121

Size: 78, 23

ControlClick Coords: 30, 16

Style: 0x50010000

ExStyle: 0x00000004

Handle: 0x00090878

>>>> Mouse <<<<

Position: 559, 390

Cursor ID: 0

Color: 0xD4D4D4

>>>> StatusBar <<<<

>>>> Visible Text <<<<

Do you want to run or save this file?

Name:

VGE.exe

Type:

Application

From:

fileshare239.depositfiles.com

&Run

&Save

Cancel

While files from the Internet can be useful, this file type can potentially harm your computer. If you do not trust the source, do not run or save this software. <A>What’s the risk?</A>

>>>> Hidden Text <<<<

Publisher:

Al&ways ask before opening this type of file

Link to comment
Share on other sites

It looks like you are on the right track. If you still have no joy start using WinGetHandle and ControlGetHandle to make sure your params are correct.

If WinWaitActive("File Download - Security Warning") Then ; you know it is going to appear
    ControlSend("File Download - Security Warning", "Do you want to run or save", "[CLASS:Button; INSTANCE:2]", "{ENTER}") ; you can add TEXT: there too.
    ControlSend("Button pressed" & @CRLF)
EndIf

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

It looks like you are on the right track. If you still have no joy start using WinGetHandle and ControlGetHandle to make sure your params are correct.

If WinWaitActive("File Download - Security Warning") Then ; you know it is going to appear
    ControlSend("File Download - Security Warning", "Do you want to run or save", "[CLASS:Button; INSTANCE:2]", "{ENTER}") ; you can add TEXT: there too.
    ControlSend("Button pressed" & @CRLF)
EndIf

Woot thanks! I'll keep at it, hopefully this works..:)
Link to comment
Share on other sites

Woot thanks! I'll keep at it, hopefully this works..:)

My bad - ControlSend("Button pressed" & @CRLF) should have been ConsoleWrite. I want to make sure it went into the if statement. Its important you know what is going on in your program or you will assume something is happening but it is not (example WinExists("File Download - Security Warning") fails so ControlSend is never run and but you think ControlSend is the issue). It was a common mistake I use to make. #AutoIt3Wrapper_Run_Debug_Mode=Y can be very handy as well.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

My bad - ControlSend("Button pressed" & @CRLF) should have been ConsoleWrite. I want to make sure it went into the if statement. Its important you know what is going on in your program or you will assume something is happening but it is not (example WinExists("File Download - Security Warning") fails so ControlSend is never run and but you think ControlSend is the issue). It was a common mistake I use to make. #AutoIt3Wrapper_Run_Debug_Mode=Y can be very handy as well.

Yeah I see what you mean, I'll keep that in mind. This is a bot for a request I got for deposit files. Aswell as the ConsoleWrite didn't work. I see it must be the WinExists. Maybe WinActivate?
Link to comment
Share on other sites

Yeah I see what you mean, I'll keep that in mind. This is a bot for a request I got for deposit files. Aswell as the ConsoleWrite didn't work. I see it must be the WinExists. Maybe WinActivate?

ConsoleWrite didn't work or didn't run. ConsoleWrite outputs to the site debug window and works 99% of the time, ConsoleWriteError will always work.

Give this a try

Opt("WinWaitDelay", 1000)
If (WinWaitActive("File Download - Security Warning") = 0) Then
    MsgBox(0, "Timeout", "Window not seen")
    Exit
EndIf
Local $winHwd = WinGetHandle("File Download - Security Warning");
ConsoleWriteError("Win Handle is " & $winHwd & @CRLF) ; first check. You should seen a handle
Local $ctrlHwd = ControlGetHandle($winHwd, "", "[CLASS:Button; INSTANCE:2]") ;~ or Local $ctrlHwd = ControlGetHandle($winHwd, "", "4427")
ConsoleWriteError("Control Handle is " & $ctrlHwd & @CRLF) ; second  check. You should seen a handle
ControlSend($ctrlHwd, "", "", "{ENTER}")

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

ConsoleWrite didn't work or didn't run. ConsoleWrite outputs to the site debug window and works 99% of the time, ConsoleWriteError will always work.

Give this a try

Opt("WinWaitDelay", 1000)
If (WinWaitActive("File Download - Security Warning") = 0) Then
    MsgBox(0, "Timeout", "Window not seen")
    Exit
EndIf
Local $winHwd = WinGetHandle("File Download - Security Warning");
ConsoleWriteError("Win Handle is " & $winHwd & @CRLF) ; first check. You should seen a handle
Local $ctrlHwd = ControlGetHandle($winHwd, "", "[CLASS:Button; INSTANCE:2]") ;~ or Local $ctrlHwd = ControlGetHandle($winHwd, "", "4427")
ConsoleWriteError("Control Handle is " & $ctrlHwd & @CRLF) ; second  check. You should seen a handle
ControlSend($ctrlHwd, "", "", "{ENTER}")

I'm gonna murder it. It didn't work, thanks though for all your help. ;).. Here is the whole loop code, the meat of the bot. It was to download a file, and delete it. Repeat.

Func button1()
$current = 1
$proxylist = StringSplit(GUICtrlRead($proxies),@CRLF)
    If $current = UBound($proxylist) - 1 Then
        MsgBox(0,'','All proxies have been used')
    EndIf
$url = GuiCtrlRead($input1)
$proxies = GuiCtrlRead($proxies)
For $i = $current To UBound($proxylist) - 1
        $current = $i
        IniWrite($file,'Current','proxy',$current)
        If $running = 0 Then Return

            $Browser = GUICtrlCreateObj($oIE,5,155,385,300)
            FtpSetProxy(2,$proxylist[$i])
                _IENavigate($oIE,$url)
                    $oForm = _IEFormGetCollection($oIE,1)
                        $oButton = _IEFormElementGetCollection($oForm,0)
                    _IEAction($oButton,'click') 
Opt("WinWaitDelay", 1000) 
                If (WinWaitActive("File Download - Security Warning") = 0) Then     
                    MsgBox(0, "Timeout", "Window not seen")     
                    Exit 
                EndIf 
    Local $winHwd = WinGetHandle("File Download - Security Warning"); 
        ConsoleWriteError("Win Handle is " & $winHwd & @CRLF) ; first check. You should seen a handle 
    Local $ctrlHwd = ControlGetHandle($winHwd, "", "[CLASS:Button; INSTANCE:2]") ;~ or Local $ctrlHwd = ControlGetHandle($winHwd, "", "4427") 
        ConsoleWriteError("Control Handle is " & $ctrlHwd & @CRLF) ; second  check. You should seen a handle 
        ControlSend($ctrlHwd, "", "", "{ENTER}")
        
            Sleep(350)
            Send("File")
            FileDelete("C:\Documents and Settings\Dell Customer\My Documents\File.exe")
            _GUICtrlStatusBar_SetText($status,'Downloads Completed :  ' & $i)
Next

    

EndFunc

Sorry for all the trouble. :) I admire what you've taught me over just this thread.

Link to comment
Share on other sites

What did ConsoleWriteError give?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

I didn't say anything. To make sure, where do you look exactly? When I ran it, nothing happened when the pop-up box came up, and when I Stopped the script, it just said abrupt termination. Exit Code 1. Sorry I'm a noob coder I guess. :) Not used to ConsoleWrite or anything.

Link to comment
Share on other sites

If you get the message box then it failed, I called Exit after that. it means the WinWaitActive timed out. How long between _IEAction($oButton,'click') (the button being clicked) and the pop-up appearing? if its some time, adjust Opt("WinWaitDelay", 1000).

Edit: Opt("WinWaitDelay", 1000) should be up the top of the script :) Don't worry everyone was a noob at some time.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Not sure mate. If you can get good info from the auto it tool you should be able to get a handle. Even if you set focus to the control then use normal send. Take a break then go back to it, I find the answers pop out then :) Good luck.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
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
 Share

  • Recently Browsing   0 members

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