With WinAppDriver and VB.NET, I am trying to get an item selected in a Combobox. I need to select it directly, not by keyboard typing or cursor key navigation as that triggers other program actions on the not-to-be-selected items.
I've been trying to select the item with .FindElementByXPath
and .click
.
I used WinAppRecorder to get the xpath, which I removed unnecessary repeating identifiers from. The following xpath and code works to get the combobox to drop down:
Dim xStateCbo As String = "/Pane[@Name=""Desktop 1""][@ClassName=""#32769""]/Window[@AutomationId=""WorkItemForm""]/Window[@AutomationId=""ADlg""]/Pane[@AutomationId=""flpMain""]/Pane[@AutomationId=""pnlTopSection""]/Pane[@AutomationId=""pnlState""]/ComboBox[@AutomationId=""cboState""]"
ProgramSession.FindElementByXPath(xStateCbo).Click()
Threading.Thread.Sleep(1000) 'make sure cbo has time to open
After getting the cbo to drop down, I then try to select the desired item by clicking on it.
Recording a click with the WinAppRecorder, I get this code (converted to VB.NET):
Dim xp4 As String = "/Pane[@Name=""Desktop 1""][@ClassName=""#32769""]/List[@Name=""State of Residence: ""][@ClassName=""ComboLBox""]/ListItem[@Name=""DELAWARE""]"
ProgramSession.FindElementByXPath(xp4).Click()
(Note that the xpath for clicking the item in the open cbo is shorter than for clicking the cbo in the first place, likely because of the way that some cbos open in a higher level. I think this is normal and not related to the problem.)
The above code should now find and click "DELAWARE" in my now-open combobox, but instead I get the standard exception for not finding an element:
System.InvalidOperationException: 'An element could not be located on the page using the given search parameters.'
It's not a casing issue, everything in the cbo is all in caps. It's not a timing issue, as I've made sure the cbo is fully dropped-down and populated.
I've also tried searches with clicks also with .FindElementByName
, etc. and identifiers from Inspect.exe, but no luck with those either. I don't care what solution is used to select the target items. I'm open to whatever works reliably.