Jump to content

Unable to click on button


VeeDub
 Share

Recommended Posts

Hi,

Looking for some advice on how to troubleshoot detection of a popup window.

I am playing around with Outlook COM on my Personal Folders. A few of these messages are encrypted with PGP so when the script reaches these messages a PGP password dialog box appears; you enter the passphrase to decrypt the message or click the Cancel button to ignore the message.

For the purposes of my testing I want to ignore these messages therefore I want the script to click on the Cancel button, I have been trying to use Adlib to achieve this without success.

Here is the details of the pop-up window from Window Info

Press CTRL-ALT-F to freeze the display.

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<
Title:  PGP Enter Passphrase for a Listed Key
Class:  #32770
Size:   X: 441  Y: 251  W: 398  H: 264

>>>>>>>>>>> Mouse Details <<<<<<<<<<<
Screen: X: 811  Y: 491
Cursor ID:  2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<
RGB:    Hex: 0xEFEBDE   Dec: 15723486

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<
Size:       X: 306  Y: 200  W: 75   H: 23
Control ID: 2
ClassNameNN:    Button2
Text:       &Cancel
Style:      0x50010000
ExStyle:        0x00000004

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<


>>>>>>>>>>> Visible Window Text <<<<<<<<<<<
Please enter your passphrase:
&OK
&Cancel
Message was encrypted to the following public key(s) :
Hide T&yping

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<
It is not possible to decrypt this message because your keyring does not contain usable private key(s) corresponding to any of the above public key(s).
Note: Caps Lock is down. Passphrases are case-sensitive.

and here is the Adlib code

Func WhackDialog()
 
    If WinExists("PGP Enter Passphrase") Then
        MsgBox(0,"Window","Exists")
        ControlFocus("PGP Enter Passphrase for a Listed Key","","Button2")
        ControlClick("PGP Enter Passphrase for a Listed Key", "", "Button2","right")
        ControlSend("PGP Enter Passphrase for a Listed Key","","Button2","!c")
    Else
        MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

No matter what I try I was never able to click on the Cancel button, eventually I began to wonder if there was a problem with the WinExists condition and sure enough the code always loops through the "does not exist" condition ... but I don't understand why as I have confirmed that I am identifying the title correctly.

Suggestions on things to try would be great.

Thanks

VW

Link to comment
Share on other sites

Perhaps try Opt(WinTitleMatchMode, "2") ?

Edit: Or try matching window text as opposed to title.

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Perhaps try Opt(WinTitleMatchMode, "2") ?

Edit: Or try matching window text as opposed to title.

Hi Mike,

Thanks for the suggestion, matching on the window text instead of the title does get the WinExists function to recognise the dialog box, which is a start. But now the Control statements don't click on the Cancel button ;)

I notice when the script is executing, that the message box for "Window Exists" doesn't appear until after I hit the Cancel button on the PGP dialog box, which makes me wonder whether the WhackDialog function is not being executed until after some input has been sent to the dialog box (which means that the Control statements will never be executed).

If that is the case, is there a better way of dealing with this dialog box, maybe Adlib isn't the best option. I have used Adlib when working with dialog boxes that appear when using IE, so I just assumed that it would be the way to respond to this dialog box.

VW

Link to comment
Share on other sites

Are you running AdlibEnable("WhackDialog")?

Also curious, why are you right clicking the cancel button? ;)

In any case, my advice would be to again use text to match the window for the ControlClick or ControlSend as well. I think if you go:

ControlClick("", "text", controlID)

it will match the last active window, so maybe WinActivate your pop up first.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Are you running AdlibEnable("WhackDialog")?

Hi Mike,

Here is the current code that I am using:

For $Folder = 1 To $Folder_Root.Folders.Count
    
    FileWriteLine($Event_Log,"Folder: " & $Folder_Root.Folders.Item($Folder).Name & @TAB _
                    & $Folder_Root.Folders.Item($Folder).Items.Count)
    
    If $Folder_Root.Folders.Item($Folder).Name = "Inbox" Or _
    $Folder_Root.Folders.Item($Folder).Name = "Sent Items" Then

        For $position = 1 To $Folder_Root.Folders.Item($Folder).Items.Count
            
            $message = $Folder_Root.Folders.Item($Folder).Items($position)
                        
;           Check whether message in date range 
            AdlibEnable("WhackDialog")
            $Message_Year = StringLeft($message.CreationTime,4)
            AdlibDisable()
;           $Message_Mon = StringMid($message.CreationTime,5,2)
            
            If @YEAR - $Message_Year > 1 Then
                ContinueLoop
            EndIf   

        Next

    EndIf

Next    
    
Func WhackDialog()
 
    If WinExists("","Please enter your passphrase") Then
  WinActivate("","Please enter your passphrase")
        MsgBox(0,"Window","Exists")
        ControlFocus("","Please enter your passphrase",2)
        ControlClick("", "Please enter your passphrase", 2,"right")
        ControlSend("","Please enter your passphrase","Button2","!c")
    Else
        MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

When I attempt to check the message to see if it is in the date range, if the message is encrypted then the PGP dialog box appears, so I use

AdlibEnable("WhackDialog")
before this step.

Also curious, why are you right clicking the cancel button? ;)

From my reading of the help on ControlClick, I am trying to click on the button on the right-hand side of the dialog box (there are two buttons <OK> and <Cancel>), rather than right-click on the left-hand side button. Am I misunderstanding how this parameter operates?

In any case, my advice would be to again use text to match the window for the ControlClick or ControlSend as well.

After making the change to WinExists, I also changed the matching/selection criteria for the Control statements as well.

I think if you go:

ControlClick("", "text", controlID)

it will match the last active window, so maybe WinActivate your pop up first.

I tried adding the WinActivate statement, but it didn't make any difference and as the dialog box already has focus at this point that isn't surprising.

The problem I think is that the "Window Exists" message box does not appear until after I hit the cancel button on the PGP Dialog box - which I think means that the WhackDialog function is not being executed until after I hit the cancel button - it's like the code is waiting for something.

The PGP dialog box is waiting for the passphrase to be entered, but if I type Alt-C, then that clicks the Cancel button and the dialog box disappears. I've just now tried using

Func WhackDialog()
 
    If WinExists("","Please enter your passphrase") Then
        WinActivate("","Please enter your passphrase")
        Send("!c")      
        MsgBox(0,"Window","Exists")
;       ControlFocus("","Please enter your passphrase",2)
;       ControlClick("", "Please enter your passphrase", 2,"right")
;       ControlSend("","Please enter your passphrase","Button2","!c")
    Else
        MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

But once again the "Window Exists" message box does not appear until after I type Alt+C or use the mouse to hit the Cancel button, this is the issue, somehow the PGP passphrase inputbox is messing with the WhackDialog function

VW

Link to comment
Share on other sites

From my reading of the help on ControlClick, I am trying to click on the button on the right-hand side of the dialog box (there are two buttons <OK> and <Cancel>), rather than right-click on the left-hand side button. Am I misunderstanding how this parameter operates?

Yes, I believe you are. ;) Which "button" it is hitting is referring to the mouse button. Change that to "left" or leave it as the default.

Also, if your function isn't adlibbing until after you click the cancel button, I would suggest pulling the AdlibEnable() out of your For loop. If it doesn't harm anything you might as well have it enabled as soon as your script starts up. Hopefully that helps.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Yes, I believe you are. :lmao: Which "button" it is hitting is referring to the mouse button. Change that to "left" or leave it as the default.

Also, if your function isn't adlibbing until after you click the cancel button, I would suggest pulling the AdlibEnable() out of your For loop. If it doesn't harm anything you might as well have it enabled as soon as your script starts up. Hopefully that helps.

If I place the AdlibEnable outside of the For loop it looks like the performance of the script is affected massively. Although there is no CPU load, no dialog boxes appear but the script never finishes, so it either the script is running incredibly slowly or it is paused.

As the Adlib function is called every 250ms, I'm not sure that it is a good idea to call it outside of the For loop because in the ordinary scheme of events the For loop could run for quite a while processing messages - and only a relative handful of messages are encrypted with PGP.

So I have left the AdlibEnable inside the For loop and modified the WhackDialog function

Func WhackDialog()
 
    If WinExists("","Please enter your passphrase") Then
        WinActivate("","Please enter your passphrase")
        ControlFocus("","Please enter your passphrase","Button2")
        Send("!C")      
        MsgBox(0,"Window","Exists")
;       ControlSend("","Please enter your passphrase","Button2","!c")
    Else
        MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

With this code probably 3 times out of 4, the dialog box is closed - but of course I get my MsgBox. If I remove the MsgBox then the dialog box always appears ;) . I have tried adding a sleep statement inside the function, so far without result.

This dialog box is a PITA

Link to comment
Share on other sites

You can change the amount of time between function calls with AdlibEnable, it is the second optional parameter. For most purposes involving window checking, I find 5 seconds is more than adequate, letting my scripts run for the majority of the time. Adjust it to whatever you think is appropriate. Did you try the ControlClick method with a "left" click? I'm running out of ideas, don't suppose you could provide a reproducer?

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

You can change the amount of time between function calls with AdlibEnable, it is the second optional parameter. For most purposes involving window checking, I find 5 seconds is more than adequate, letting my scripts run for the majority of the time. Adjust it to whatever you think is appropriate. Did you try the ControlClick method with a "left" click? I'm running out of ideas, don't suppose you could provide a reproducer?

I agree with mikehunt114; try right clicking on a dialog box button. See what happens. Nothing.

That is exactly what your script is doing at that point.

Link to comment
Share on other sites

Or instead of

ControlSend("","Please enter your passphrase","Button2","!c")oÝ÷ ÚÚòjëh×6ControlSend("","Please enter your passphrase","Button2","{Enter}")

or perhaps {SPACE}.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

and here is the Adlib code

Func WhackDialog()
 
    If WinExists("PGP Enter Passphrase") Then
        MsgBox(0,"Window","Exists")
        ControlFocus("PGP Enter Passphrase for a Listed Key","","Button2")
        ControlClick("PGP Enter Passphrase for a Listed Key", "", "Button2","right")
        ControlSend("PGP Enter Passphrase for a Listed Key","","Button2","!c")
    Else
        MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc
Does the cancel button have to be right clicked? Most of the time cancel buttons don't respond to right clicks, as far as i know.

ControlClick("PGP Enter Passphrase for a Listed Key", "", "Button2")

I apologize if this has already been tried and i just missed it while skimming through this thread.

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Here's an extract from Window Info

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<
Please enter your passphrase:
&OK
&Cancel
Message was encrypted to the following public key(s) :
Hide T&yping

Here's my most recent WhackDialog function

Func WhackDialog()
 
    If WinExists("","Please enter your passphrase") Then
        $Status = WinActivate("","Please enter your passphrase")        
        If $Status = 1 Then
            $Status = ControlFocus("","","1239")
            $Status = ControlSend("","",1239,"{TAB}{TAB}{Enter}")
            MsgBox(0,"Control",$Status)
        EndIf       
    Else
;       MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

The WinExists test works, The WinActivate test works. So that says the script can "see" Visible Window Text. I don't know whether the fact that the script appears to be able to "see" the Visible Window Text can be used to my advantage but whether I try to Send/ControlSend "{TAB}{TAB}{Enter}" or "!c", nothing works as far as trying to get the script to hit the cancel button.

There is another approach to consider. When I read the message

$message = $Folder_Root.Folders.Item($Folder).Items($position)
the dialog box doesn't appear.

It is not until I check the message creation time

$Message_Year = StringLeft($message.CreationTime,4)
that the dialog box appears.

So that suggests that there may be a property that I can check to ascertain whether the message is encrypted or not, but the question is which property item?

Is there an easy way that I can dump all the property items for a message so that I can compare two messages?

VW

Link to comment
Share on other sites

Here is something interesting

Func WhackDialog()
 
    If WinExists("","Please enter your passphrase") Then
        $Status = WinActivate("","Please enter your passphrase")        
        If $Status = 1 Then
            $Status = WinClose("","Please enter your passphrase")       
            MsgBox(0,"Control",$Status)
        EndIf       
    Else
;       MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

WinClose gives a Status of 1, but closes SciTE rather than the PGP dialog box (?)

Link to comment
Share on other sites

Found the classname from Window Info

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<
Title:  PGP Enter Passphrase for a Listed Key
Class:  #32770

Changed WinTitleMatchMode

AutoItSetOption("WinTitleMatchMode",4)

Func WhackDialog()
 
    If WinExists("classname=#32770","") Then
        $Status = WinClose("classname=#32770","")       
        MsgBox(0,"WinClose",$Status)
    Else
        MsgBox(0,"Window","does not exist")
    EndIf
    
EndFunc

WinClose reports $status of 1 - after I manually close the PGP Dialog box. That is, WinClose reports that it is successful, even though it isn't ;)

Link to comment
Share on other sites

I believe if you use "" to match the window title is matches the last active window. Sorry if I told you otherwise. So if it's trying to WinClose, it correctly ascertains that the window exists. Try WinKill on the window.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Hi Mike,

WinKill doesn't work any better than WinClose.

For what ought to be a "simple" task this seems to becoming quite complex. If you forget about the script for a moment, when the dialog box appears I can do the following myself:

- use the mouse to click on the cancel button

- type ALT-C

- type tab tab enter

Yet I can perform none of these actions with AutoIt, in your experience are there some dialog boxes that are somehow "non-standard" and are difficult to work with?

Also I'm sorry but I don't understand the point that you were making in your last post

I believe if you use "" to match the window title is matches the last active window. Sorry if I told you otherwise.

I don't feel that I've been mislead at all, but I don't understand the implications of the point you're making, I assume it may have some bearing on some of my earlier attempts to close this annoying dialog box, would appreciate if you could clarify.

Thanks very much for your assistance, I'm fed up with this dialog box, but if I didn't have someone to bounce ideas off I would be going nuts. ;)

Cheers,

VW

Link to comment
Share on other sites

What I meant was, if you do the following:

WinExists("", "text")

you will get a result from the most recently active window with "text" in it. Hopefully that's clear now.

What I don't understand is how you can get the correct return from WinExists and using the same parameters you aren't able to control it? Maybe there is a small typo somewhere or something. It has not been my personal experience that many windows are not able to be controlled with the AutoIt. There are of course a few exceptions that I have heard of, I think MSN is one. In any case, I think I am outta ideas here man (unless you can provide a reproducer?), but this post will put you at the top of the forums, hopefully someone smarter than I can help you out mate.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

OK here is the latest function

Func WhackDialog()
 
    $WE_Status = WinExists("classname=#32770","")
    ConsoleWrite("WE Status: " & $WE_Status & @CRLF)
    If $WE_Status = 1 Then
        $WA_Status = WinActivate("classname=#32770","")     
        ConsoleWrite("WA Status: " & $WA_Status & @CRLF)
        If $WA_Status = 1 Then
            $CF_Status = ControlFocus("","","Button2")
            $CC_Status = ControlClick("","","Button2")
            ConsoleWrite("CF Status: " & $CF_Status & @TAB & "CC Status: " & $CC_Status & @CRLF)
        EndIf       
    Else
        MsgBox(0,"Window","does not exist")
    EndIf

EndFunc

This function reports Status code of 1 for all the functions (WinExists, WinActivate, ControlFocus, ControlClick) after I have manually clicked on the Cancel button on the PGP dialog box.

Before I click on the Cancel button, there are no values written to the Console, that is, the WhackDialog function is somehow "paused".

At the very least, if the function were working as I expected, it should write the "WE Status" to the console immediately the function is called - but until I click on the Cancel button on the dialog box it is like the whole AutoIt script is paused.

Link to comment
Share on other sites

Sounds like your Adlib isn't set up quite right?

Edit: In having a look at your entire code on the first page of this topic (are you still using the same?), I noticed that you are AdlibDisabling before your functions even has a chance to run. You should probably use a timer (parameter in AdlibEnable), or else AdlibDisable once you have stopped the process that can cause the PGP pop-up. Eureka?

Edited by mikehunt114
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
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...