C# Windows UI自动化:如何将自动化ID设置为HTML元素?
我正在为桌面应用程序使用Windows UI自动化。UI自动化似乎也能够在embedden WebBrowser控件的HTML中找到元素,但我找不到一种方法为这些元素提供自动化ID 我试过这些:C# Windows UI自动化:如何将自动化ID设置为HTML元素?,c#,microsoft-ui-automation,C#,Microsoft Ui Automation,我正在为桌面应用程序使用Windows UI自动化。UI自动化似乎也能够在embedden WebBrowser控件的HTML中找到元素,但我找不到一种方法为这些元素提供自动化ID 我试过这些: <button id="MyButton" >My Button</button> <button data-automation-id="MyButton" >My Button</button> <button AutomationPropert
<button id="MyButton" >My Button</button>
<button data-automation-id="MyButton" >My Button</button>
<button AutomationProperties.AutomationID="MyButton" >My Button</button>
这很好,我的HTML按钮被识别,但没有自动ID
当然,我可以改为使用“Name”属性,但每当按钮文本发生更改时,这可能会中断我的代码
public AutomationElement AutomationElementFromCursor()
{
var pt = Forms.Cursor.Position;
return AutomationElement.FromPoint( new Point( pt.X, pt.Y ) );
}