Jump to content
Sign in to follow this  
Wadams

_GUICtrlListView_ClickItem won't click some items

Recommended Posts

Autoit newbie here. 

I'm trying to use Autoit to automate an action in VMWare's Vsphere client.  I've got about 1/2 of it working but am running into a problem trying to click on an item in a ListView.  I've detected the window, found the listview, even found the item that I want to click, but when I use _GUICtrlListView_ClickItem to click it, the mouse moves to the item, but it does not get selected.   I did some testing and wrote a loop to select every item, one at a time, in the list.  The mouse moves to every item, but only 7 of the 10 rows/items can be selected (by AutoIT).  The other 3, including the one I want, won't select.   All of the items are selectable if I manually use the mouse.  I've tried changing the number of clicks and the delay, but nothing seems to work.
 

Here's my test code:

 

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
Local $hWnd1, $hWnd2, $hTV, $hLV, $hTMP, $sText


WinWaitActive("Add Hardware")
Local $hWnd3 = WinGetHandle("[CLASS:WindowsForms10.Window.8.app.0.ef627a; TITLE:Add Hardware]", "")
If @error Then
   MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Add Hardware")
   Exit
 EndIf
$hLV = ControlGetHandle($hWnd3, "", "[CLASS:WindowsForms10.SysListView32.app.0.ef627a; INSTANCE:1]")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Hardware device syslist.")
    Exit
 EndIf

$hTMP = _GUICtrlListView_FindInText($hLV, "USB Device")

If $hTMP Then
   For $i = 0 to _GUICtrlListView_GetItemCount($hLV)-1
      _GUICtrlListView_ClickItem($hLV, $i, "left", True, 1,20)
   Next

  ;_GUICtrlListView_ClickItem($hLV, 7, "left", True, 2)
  ;_GUICtrlListView_ClickItem($hLV, $hTMP, "left", True, 20)
 Else
   ConsoleWrite("'USB Device' item not found")
   Exit
 EndIf

 

And I've attached an image of  the window I'm working with.

 

It will select every item except, "CD/DVD Drive", "USB Device" (which is the one I want to select), and "Hard Disk".

 

Any help would be appreciated!

 

Wayne

snap_20170210_122423.jpg

Share this post


Link to post
Share on other sites

Just out of curiosity, have you looked at the PowerCLI scripts? The scripts (which can all be called from an AutoIt script) can natively add pretty much any device you want to the VM with one or two lines. Much easier than trying to manipulate the GUI of a desktop client that is soon to be discontinued.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

I would love to (and I've tried), but I'm using the free version of ESXi, and the powercli stuff to add/remove USB devices is only available with the paid version.

Share this post


Link to post
Share on other sites

@Wadams I tried your code out, and it selected only those items where the text was long enough to fall under the mouse cursor. Is this what you're experiencing?

 

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

@JLogan3o13 Yeah, looking at it, I didn't catch the string length correlation.  Though, is it correlation or coincidence?

@Subz Thanks!  I didn't know that about GuiCtrl functions.

 

I replaced the 2nd half of the script with the following and it seems to work!

Local $hLV_ItemIdx = ControlListView($hLV, "", "", "FindItem", "USB Device")


If $hLV_ItemIdx = -1 Then
   ConsoleWrite("Could not find string USB Device in LV" & @CRLF)
   Exit
EndIf

ControlListView($hLV, "", "", "Select", $hLV_ItemIdx)

 

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...