Jump to content
Sign in to follow this  
RS_Ana

FindString not selecting correct combobox option

Recommended Posts

I am trying to select a specific option from the combobox. I have tried so many ways but the only way I am able to select combobox is via below code but the issue is it selecting wrong option.

Here is my code:

$databasename = "AutoITDB1"

ControlCommand ('TestSystem', '', '[CLASS:WindowsForm10.Button_1_0_141b42a; INSTANCE:1]', 'FindString', $databasename)

ControlSend('TestSystem', '', '[CLASS:WindowsForm10.Button_1_0_141b42a; INSTANCE:1]', 'select', $databasename)

 

Its not selecting database with name AutoITDB1 from the dropdown but just some random db. Tried almost all solutions with no success. Any help is really appreciated. Attaching screen shot for ref. 

 

AutoIT.png

Share this post


Link to post
Share on other sites

Hi @RS_Ana, and welcome to the AutoIt forum :)

What are the return values from both functions? :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

If I do something like this 

$test = ControlCommand ('TestSystem', '', '[CLASS:WindowsForm10.Button_1_0_141b42a; INSTANCE:1]', 'FindString', $databasename)

MsgBox(0, 'DB Name', $test, 10)

I get 0 in the msg box pop up. 

 

I tried with direct database name as well but as usual it just selects some other db . Like this

ControlCommand ('TestSystem', '', '[CLASS:WindowsForm10.Button_1_0_141b42a; INSTANCE:1]', 'FindString', 'AutoITDB1')

Just banging my head all over the place lol....

Share this post


Link to post
Share on other sites

Resolved the issue with this code:

ControlFocus("Window Title", "", "ControlID")

While 1

Send ("{Down}")

$dbName = ControlCommand ("Window Title", '', "[CLASS:WindowsForm10.Button_1_0_141b42a; INSTANCE:1]")

If $dbName = $databasename

ExitLoop

EndIf

WEnd

Share this post


Link to post
Share on other sites

You need to do the controlcommand selectstring (you are using an invalid option of "select") on the combo box, not on a button.

As a side note, you can easily debug these failures by looking at the @error, to see what the failure reason was

Read about all the options in the help file:

Controlcommand

 

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Can any one help, the exact script which is working in windows 2012 is not working in Windows2016 server.

ControlFocus($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
MsgBox(0, "Database Name", $databasename)
Sleep(5000)
While 1
    Send("{Down}")
    Sleep(300)
    $dbName = ControlGetText($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
    MsgBox(0, "Database Name", $dbName)
    Sleep(300)
    If $dbName = $databasename Then
        MsgBox(0, "Database Name", "Provided Database Found")
        ExitLoop
    Else
        MsgBox(0, "Database", "Provided database does not exists.")
        Exit
    EndIf
WEnd
Sleep(1000)
WinActivate($dbUtilityWindowTitle)

The MsgBox I am using is just to debug it. My $databasename is calling correct value but $dbName is showing the default value populated in dropdown which is "Create New database". The Send("{Down}") is not sending down action on combobox and directly else loop is executing and show msgbox "Provided database does not exists".

I am not sure why send down is not working in win 2016 server.

Any help is really appreciated.

Share this post


Link to post
Share on other sites

Send is not a reliable function.  You can make it a bit more reliable by making sure you control is in focus, and your window is active

 

WinActivate

ControlFocus

 

Then you have to take into consideration that autoit might send too quickly for the application to read, or the delay between character sends is too short...which can be modified via

AutoItSetOptions

 

 

Use ControlCommand with 'selectstring'...extremely reliable.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

jdelaney I updated the code to:

WinActivate($dbUtilityWindowTitle)
ControlFocus($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
Sleep(3000)
While 1
    Send("{Down}")
    Opt("SendKeyDelay", 1000)
        $dbName = ControlGetText($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
        MsgBox(0, "DB Name from DD", $dbName, 2)
        If $dbName = $databasename Then
            MsgBox(0, "Database Name", "Provided Database Found")
            ExitLoop

        EndIf
WEnd

And the issue is First down key happens and moves to first entry of dropdown and I get the DB name as first entry of db dropdown and after that down is not happening because the same MsgBox comes and goes after 2 sec with only forst combobox entry. Its not going to 3, 4, 5.. combo box entries until I click ok from the Msg Box (before 2 sec). If I click Ok on MsgBox it goes to second combo box option again click Ok of MsgBox and it will go next.

I have no idea y this is happening.

I tried with CommandControl but no success.

Share this post


Link to post
Share on other sites

I'm not going to help you hack a send...try with the controlcommand, or wait for someone who will help you with the send.

Start by getting the control as a handle, and verifying that:

$hControl = ControlGetHandle($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")

MsgBox(1,1,$hControl)

If that message box displays the same handle for the control, as you see in the auto it spy tool, then do this:

ControlCommand($dbUtilityWindowTitle,"", $hControl, "SelectString", $databasename)

 

If the message box doesn't return the correct handle, you need to find a better way to find your control.

 

I know it's a personal preference not to use send (except as a very last resort), but take some advice from me...if you want a script that will work greater than 80-90% of the time, you'll go  with the controlcommand route.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

jdelaney the sol you suggested didn't work :(. So I modified the code as :

WinWaitActive($dbUtilityWindowTitle, "", 10)
ControlFocus($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
Sleep(3000)
ControlClick($dbUtilityWindowTitle, "", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
Local $hControl = ControlGetHandle($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]")
ControlCommand($dbUtilityWindowTitle,"", $hControl, "SelectString", $databasename)
;Sleep(5000)
;MsgBox(1,1,"Success",10)
ControlCommand($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.COMBOBOX.app.0.141b42a_r6_ad1; INSTANCE:1]", "SetCurrentSelection", $databasename)
Sleep(2000)
WinActivate($dbUtilityWindowTitle)
$warningMgsRef = ControlGetHandle($dbUtilityWindowTitle,"", "[CLASS:WindowsForms10.STATIC.app.0.141b42a_r6_ad1; INSTANCE:5]")
Switch $warningMgsRef
    Case $warningMgsRef
        MsgBox(0, "Database", "Database overwrite is called", 5)
        ControlClick("GVE - Database Utility","", "[CLASS:WindowsForms10.BUTTON.app.0.141b42a_r6_ad1; INSTANCE:6]")
    Case Else
        MsgBox(0, "Database", "No data found", 5)
EndSwitch

 

ControlClick(line 4) is clicking on the dropdown but after that    MsgBox(0, "Database", "Database overwrite is called", 5) is executing which will happen only if database is found :blink: but the dropdown remains selected to default option which is "Select a database" :'(.

Any solution for my prob?:(

 

Share this post


Link to post
Share on other sites

Hello. You can do it by Index Something like this:

#include <GuiComboBoxEx.au3>

Local $hControl=ControlGetHandle("GVE - Database Utility","","WindowsForms10.BUTTON.app.0.141b42a_r6_ad16")
_GUICtrlComboBoxEx_SetCurSel ( $hControl ,1)
 

 

Saludos

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...