【发布时间】:2020-02-13 03:44:00
【问题描述】:
我是自动化新手,我正在尝试使用带有 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");
【问题讨论】:
-
您尝试过这些不同的方法吗? github.com/microsoft/WinAppDriver/wiki/…
-
我尝试使用 FindElementByAccessibilityId 和 FindElementByName。其他我没有。我希望它至少应该与 FindElementByAccessibilityId 一起使用。
-
代替sendkeys,尝试使用click()函数点击元素。首先查看您的元素是可交互的。 element.enabled == true,element.displayed == true。您需要关注的另一件事是您正在右侧窗口上工作。
-
我使用了元素的点击功能以及 aWindow.FindElementByAccessibilityId("Login").Click();但是这个语句(aWindow.FindElementByAccessibilityId("Login");) 本身正在引发异常。而且按钮是可点击的。
标签: c# appium-desktop winappdriver