我使用Selenium.Appium.Windows
为WPF
(windows演示应用程序)创建了几个测试。我正在使用WinAppDriver
来运行测试但不幸的是,一些UI测试因以下错误而失败;任何指针都将非常感激。
信息:
System.InvalidOperationException:使用给定的搜索参数无法在页面上找到元素。
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver`1.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Appium.AppiumDriver`1.FindElement(String by, String value)
at OpenQA.Selenium.Appium.AppiumDriver`1.FindElementByAccessibilityId(String selector)
启动服务器WinAppDriver
服务器及其运行
以下是我的环境细节:
WinAppDriver 1.1 version
Window 10 Pro, 32 GB RAM, i7-7500U Processor
NET Core 3.0 SDK
我们只能通过查看错误消息来解决问题。一般来说,在本网站上寻求帮助时,最好包含一个可以重现问题的代码的minimal complete verifiable example。
您的应用程序未能找到具有您要搜索的自动化ID的任何元素。诊断无法找到自动化ID的最佳方法是使用inspect.exe等工具检查您希望选择的元素,并查看其AutomationId的实际值。
您可能还想检查是否正在连接到正确的应用程序。即使你的ID存在,如果你在错误的地方寻找它,你也不会找到它。
在测试中逐步运行调试器以查看是否存在更复杂的失败原因也很有帮助,例如在搜索时未完全加载元素。