Guest phh Posted February 24, 2005 Posted February 24, 2005 This is a question which I am sure is pretty basic but I haven't found the answer after more than a few hours of trying and RTFMing. I am trying to develop a way of driving a third party application which includes a couple of dropdowns (combo boxes). I don't have access to that application right now so I have written a simulation of that application's interface in AutoIt which is working nicely when I use it from the keyboard and mouse. When I drive the simulation with an AutoIt script, sending text works fine as does selecting menu items (e.g., ALT-F). However, attempting to select a specific item from the dropdowns accomplishes absolutely nothing. I tried a lot of different functions after I had no luck with code like: ; This is in the driver program ControlCommand($title, "", 6, "SelectString", $item) where "$title" is the window title, "6" is the value I got for the combo box from Window Info, and "$item" matches the text I added with GUICtrlSetData() when building the simulation (e.g., "user1"): ; This is in the UI simulation $ctlUname = GUICtrlCreateCombo("", 90, 60, 160); GUICtrlSetData($ctlUname, "user1|user2|user3", "") Is this the basic approach I should be using when selecting from a dropdown? By the way, one thing I have noticed is the combo box seems to be two controls. There is a border which is 6 and the area in the box is 1001. Neither value works. I'm wondering if perhaps the dropdown isn't actually selected when I think it is although the cursor is in it when I think it should be and debugging MsgBoxes show the variables have the values I think they do. Thank you, -- Peter
Guest phh Posted February 25, 2005 Posted February 25, 2005 I've tried to create the simplest example code that illustrates the problem. Here it is. First is the code for the DRIVEN application which works fine when driven by the keyboard and mouse: ; Save this code as "DRIVEN.au3", compile it, and ; run the executable to see that it works fine #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Dim $btnLogin, $inpLogin, $lblLogin GUICreate("driven", 300, 150) $lblLogin = GUICtrlCreateLabel("Login", 10, 30) $inpLogin = GUICtrlCreateCombo("", 60, 30, 120) GUICtrlSetData($inpLogin, "one|two|three", "") $btnLogin = GUICtrlCreateButton("Login", 10, 60) GUICtrlSetOnEvent($btnLogin, "Login") GUISetOnEvent($GUI_EVENT_CLOSE, "Egress") GUISetState(@SW_SHOW) While 1 sleep(1000) WEnd Func Egress() MsgBox(0, "Bye!", "See you later", 5) Exit EndFunc Func Login() Dim $login = GUICtrlRead($inpLogin) MsgBox(0, "Login", "We are in Login() and the login is '" & $login & "'", 5) EndFunc Now here is the code which is supposed to drive the application above. Save it as DRIVER.au3 ; This should be run in the same directory as "DRIVEN.exe" Run("driven.exe") WinWaitActive("driven") ControlCommand("driven", "", "ComboBox1", "SetCurrentSelection", "two") ControlSend("driven", "", "Button1", "{ENTER}") I do notice that when DRIVER is run, DRIVEN behaves a little differently ("one" is selected instead of the default value of "") but it's still not what is desired. Also, the button isn't clicked by driver. Does anyone have any ideas as to what I am doing wrong? Thank you, -- Peter.
ZeDMIN Posted February 25, 2005 Posted February 25, 2005 I think i got your problems. Try this: WinWaitActive("driven") ControlCommand("driven", "", "ComboBox1", "SetCurrentSelection", 1) ControlClick('driven', '', 'Button1') The ControlCommand wants the number of the entry as value, so "0" for the first value of the combobox, "1" for the second, ... ControlClick is better for clicking buttons than sending enter.
Guest phh Posted February 25, 2005 Posted February 25, 2005 Thank you ZeDMIN! You were absolutely right. Once I modified DRIVER.au3 as below it behaved the way I wanted. ; This should be run in the same directory as "DRIVEN.exe" Run("driven.exe") WinWaitActive("driven") $ref = ControlCommand("driven", "", "ComboBox1", "FindString", "two") ControlCommand("driven", "", "ComboBox1", "SetCurrentSelection", $ref) ControlClick("driven", "", "Button1")
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now