0

I am new to automation using Appium for a C# Desktop application. I have a Username text control on screen which has an Automation Id set on it. When I attempt to click on the username field I receive the error: 'An element command could not be completed because the element is not pointer- or keyboard interactable.'

driver.FindElementByAccessibilityId("UserNameTextBox").Click();

If I add the element to a variable and inspect its properties I can see that it is set as Displayed = False, despite being on screen. I have also injected a wait of 5 seconds to be sure this isn't a timing issue.

If I attempt to use the same technique on the Password field below, it works.

Doing some further debugging, I can see that this has a TagName of Control.Text

var userNameBox = driver.FindElementByAccessibilityId("UserNameTextBox"); 

and this has a TagName of Control.Edit

var passwordBox = driver.FindElementByAccessibilityId("PasswordBox");

If I use the Inspector.exe it reveals the following properties for the username control:

enter image description here

This code successfully finds the element and clicks on it:

driver.FindElementByClassName("TextBox").Click();
driver.FindElementByClassName("TextBox").SendKeys("joe bloggs");

But this code returns the error.

driver.FindElementByAccessibilityId("UserNameTextBox").Click();
driver.FindElementByAccessibilityId("UserNameTextBox").SendKeys("joe bloggs");

Why? I would rather use Accessibility Id, there is only one instance of TextBox on screen in this example, but it won't be very reliable for other screens.

cw84
  • 2,111
  • 5
  • 24
  • 37
  • Desktop application components have no such types. There are Label, TextBox, RichTextbox etc. If the component was hidden you wouldn't see it, period. Is the ID assigned to the label instead of the TextBox perhaps? – Panagiotis Kanavos Aug 26 '21 at 15:00
  • When I use the Inspect app and click on the username field - it's the UserNameTextBox that gets returned as the Accessibility Id – cw84 Aug 26 '21 at 15:05

1 Answers1

2

Without being able to inspect your app running in a test environment it's impossible to diagnose exactly what is causing the behavior you're describing.

Let's look at what you know:

  • You can locate an element with the class "TextBox"
    • You are capable of clicking the element successfully
  • You can locate an element with the automation id "UserNameTextBox"
    • You get an error when you try to click on it

From this we can assume that driver.FindElementByClassName("TextBox") is not equal to driver.FindElementByAccessibiltyId("UserNameTextBox"). You now need to figure out how they differ.

I would recommend setting a breakpoint after locating both elements and inspecting how they differ. It's likely that they're pointing to slightly different elements in the tree. You can combine this with inspect.exe to see how they relate to each other. This should give you the information you need to determine how to use accessibilityId to locate the clickable element.

sphennings
  • 998
  • 10
  • 22