我是自动化新手,我正在尝试使用带有 C# 的 WinAppDriver 自动化 WPF 应用程序。我能够加载应用程序,但在尝试使用给定的搜索参数查找具有 Name/AccessibilityId 的元素时出现类似 {"An element could not be located on the page using the given search parameters."} 之类的错误,即使在保持等待时间后也是如此。
见下文:
POST /session/09551C9F-CF20-4C2B-A900-F17D2483F9D8/element HTTP/1.1
Accept: application/json, image/png
Content-Length: 45
Content-Type: application/json;charset=utf-8
Host: 127.0.0.1:4723
{"using":"accessibility id","value":"TxtPwd"}
HTTP/1.1 404 Not Found
Content-Length: 139
Content-Type: application/json
{"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}
我不知道发生了什么。有什么建议么?
我确实喜欢 - 通过检查工具检查元素和元素的自动化 ID/名称 - 将开发人员模式设置为活动 - 在找到元素之前等待时间
var aDesiredCapabilities = new DesiredCapabilities();
aDesiredCapabilities.SetCapability("app", @"PathToApplication");
aDesiredCapabilities.SetCapability("deviceName", "Windows 10");
var aWindow = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), aDesiredCapabilities);
aWindow.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
aWindow.FindElementByAccessibilityId("TxtPwd").SendKeys("qwerty");
aWindow.FindElementByAccessibilityId("TxtUser").SendKeys("123456");
aWindow.FindElementByAccessibilityId("Clear").Click();
aWindow.FindElementByAccessibilityId("TxtPwd").SendKeys("qwerty");
aWindow.FindElementByAccessibilityId("TxtUser").SendKeys("123456");
aWindow.FindElementByAccessibilityId("Login");