Jump to content

ControlSetText not working, sometimes


texan
 Share

Recommended Posts

I keep having a random problem with ControlSetText not working on some Windows 7 PCs. Below is the section of code that is causing me a problem. I am trying to sign on to our software application. I wait for the Sign-On window to appear and then enter the password in the Editbox using the ControlSetText command. It always works on my 2000, XP & Vista PCs but on occassion it does not work on the Win7 PCs.

Is there some other command I should try? Is there something different on Win7 that may cause this to fail at times? I am just a little lost on what to try next.

;If we find the Sign-On window then try to sign on
If WinExists("Sign-On") Then
    GUICtrlSetData($Label, "Sign-On window found.")
    Sleep(15000)
    ;SetText has been failing at times on Win7. Repeat attempt if it does.
    $Result = WinWaitActive("Sign-On", "", 20)
    If $Result = 0 Then
        FailureExit("Sign-On window not active.")
    EndIf
    $Result = ControlSetText("Sign-On", "", "[CLASS:Edit;INSTANCE:1]", $Password)
    If $Result = 0 Then
        GUICtrlSetData($Label, "Password SetText failed first attempt.")
        Sleep(5000)
        $Result = ControlSetText("Sign-On", "", "[CLASS:Edit;INSTANCE:1]", $Password)
        If $Result = 0 Then
            FailureExit("SetText of password failed.")
        EndIf
    EndIf
....
Link to comment
Share on other sites

Try this

;If we find the Sign-On window then try to sign on
If WinExists("Sign-On") Then
    GUICtrlSetData($Label, "Sign-On window found.")
    Sleep(15000)
    ;SetText has been failing at times on Win7. Repeat attempt if it does.
    WinActivate("Sign-On", "")
    $Result = WinWaitActive("Sign-On", "", 20)
    If $Result = 0 Then
        FailureExit("Sign-On window not active.")
    EndIf
    ControlFocus("Sign-On", "", "[CLASS:Edit;INSTANCE:1]")
    $Result = ControlSetText("Sign-On", "", "[CLASS:Edit;INSTANCE:1]", $Password)
    If $Result = 0 Then
        GUICtrlSetData($Label, "Password SetText failed first attempt.")
        Sleep(5000)
        ControlFocus("Sign-On", "", "[CLASS:Edit;INSTANCE:1]")
        $Result = ControlSetText("Sign-On", "", "[CLASS:Edit;INSTANCE:1]", $Password)
        If $Result = 0 Then
            FailureExit("SetText of password failed.")
        EndIf
    EndIf
....
Link to comment
Share on other sites

You can also keep trying it

Do
    $Result = ControlSetText("Sign-On", "", "[CLASS:Edit;INSTANCE:1]", $Password)
    Sleep(10)
    $Return = ControlGetText("Sign-On", "", "[CLASS:Edit;INSTANCE:1]")
Until $Result == $Return Or Not ControlGetHandle("Sign-On", "", "[CLASS:Edit;INSTANCE:1]")

Edited by Varian
Link to comment
Share on other sites

ControlCommand() with "EditPaste"

ControlCommand("Sign-On", "", "[CLASS:Edit;INSTANCE:1]", "EditPaste", $Password)

^^^ This was the solution. ControlSetText continued to fail at times even after making sure the field had focus. Also, I couldn't do anything that involved using ControlGetText because that always fails, even after successfully using ControlSetText. The field is a password field that only shows ****** so maybe that is why.
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...