1

I want to get the value from the LegacyIAccessible description property of a list item using either UI Automation or preferably FlaUI. I have the below working but it is not consistent. I am unsure why but it seems to only work if the target window is open before the test starts(using SpecFlow to run tests).

for (int i = 0; i < listbox.Items.Length, i++)
{ 
itemDesciption = listBox.Items[i].Patterns.LegacyIAccessible.PatternOrDefault.Description;
if (itemDesciption.Contains("value"))
{ 
targetItem = listBox.Items[i]; ) 
}
ilCosmico
  • 1,319
  • 15
  • 26
bradkt
  • 111
  • 1
  • 7
  • What do you mean by non consistent? Sometimes works and sometimes not? – Roemer Aug 13 '18 at 07:15
  • @Roemer yes, itemDescription would be null except when the test started with the target component open, at least that seemed to be the only difference. Recently came to find that the app under test is unmanaged. I added FlaUI2 to project and having good results to retrieve legacy property values, while FlaUI3 is able to interact with other components. Still unsure how/why it sometimes worked at all before. – bradkt Aug 13 '18 at 21:39

1 Answers1

0

Maybe you can try something like this (based on FlaUI3 version)

[TestMethod]
public void TestMethod2()
{

    var app = FlaUI.Core.Application.Launch("WindowsFormsApp1.exe");
    app.WaitWhileBusy();

    using (var automation = new UIA3Automation())
    {
       var window = app.GetMainWindow(automation);

       var listBox = window.FindFirstDescendant(cf => cf.ByAutomationId("listBox1")).AsListBox();

       foreach (ListBoxItem item in listBox.Items)
       {
           Console.WriteLine(item.Patterns.LegacyIAccessible.Pattern.Description.Value);
       }

       window.Close();
    }
}
ilCosmico
  • 1,319
  • 15
  • 26