Answered by:
UI Automation (IUIAutomationElement) and HTML Input controls?

-
I have a test harness written in C# using CUIAutomation and IUIAutomationElements to perform UI Automation.
I am pointing this test harness at HTML interfaces (both in IE and in a Silverlight HTML container, although I don't think this is actually germane to the conversation).
A number of HTML Input controls (Type = Text) are present on the page, but my harness and inspect.exe both fail to detect a useable Name ID. In hindsight, this matches the documentation available on MSDN, but that doco does not make a lot of sense. At http://msdn.microsoft.com/en-us/library/windows/apps/hh452706.aspx is a listing of the mapping of HTML 4 controls to UIA.
According to that page, an Input control where Type = Text will always have a Name = "". While this matches what I see in inspect, this doesn't make a whole lot of sense. In other words, using the Name property to identify an on-screen input control is impossible, since there is no uniquely identifying property that can be used to distinguish one control from another.
So, how is this intended to work? I am guessing I should be using an Automation ID instead, however, the same controls exhibit not such property via inspect.exe. Here is a sample of the HTML used to create the Input controls in question:
<input name="GeneralInfoPage$NameTextBox" type="text" maxlength="50" id="GeneralInfoPage_NameTextBox" class="detailText" style="width:50%;" />As you can see, both a name and ID are provided in the mark-up. Is there a tag that can be added to get a similar, unique value to be used as the Automation ID? Can I override the Name behavior?
If not, should I read between the lines and determine that UIA is an unacceptable way to perform automation against HTML since it effectively means many controls will not be uniquely identifiable and distinguishable from other controls? That doesn't make any sense to me since some controls map just fine (eg - a Button using where Name = Value property) and can be automated against without incident.
Thanks for any help
Question
Answers
-
After some trial and error I was able to get the aria-labelled property to give me a Name property. Still haven't figured out any way to populate AutomationID.
<td><span id="GeneralInfoView_PortfolioIdLabel" class="detailStrongLabel">ID</span></td> <td><input name="GeneralInfoView$PortfolioIdTextbox" type="text" maxlength="30" id="GeneralInfoView_PortfolioIdTextbox" class="detailText" aria-labelledby="GeneralInfoView_PortfolioIdLabel" style="width:80%;" /></td>
The ability to set an AutomationID would be much more useful, but maybe this will be helpful to someone else.
Can I mark my own post as the answer?
All replies
-
Have you looked into ARIA? http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452704.aspx
-
-
-
Still battling with this... I've made some attempts with ARIA to get this to work, still no useable Name or Automation ID.
Here's the HTML of an Input control:
<td><input name="GeneralInfoView$PortfolioIdTextbox" type="text" maxlength="30" id="GeneralInfoView_PortfolioIdTextbox" class="detailText" role="textbox" aria-label="PortfolioIdTextbox" style="width:80%;" /></td>
Note the use of the aria-label property which should map to UI Automation Name according to this page
And here's the Inspect output:
No Name or Automation ID.
So, can anyone please provide me with some assistance as to how to expose HTML Input Controls where type = 'Text' to UI Automation?
Thanks for any and all assistance!
- Edited by rustoleum Monday, May 12, 2014 8:48 PM
-
After some trial and error I was able to get the aria-labelled property to give me a Name property. Still haven't figured out any way to populate AutomationID.
<td><span id="GeneralInfoView_PortfolioIdLabel" class="detailStrongLabel">ID</span></td> <td><input name="GeneralInfoView$PortfolioIdTextbox" type="text" maxlength="30" id="GeneralInfoView_PortfolioIdTextbox" class="detailText" aria-labelledby="GeneralInfoView_PortfolioIdLabel" style="width:80%;" /></td>
The ability to set an AutomationID would be much more useful, but maybe this will be helpful to someone else.
Can I mark my own post as the answer?
-
You'll probably find more help with HTML in the Internet Explorer Web Development forum