Appium unable to find UI-Elements using XPath

▼魔方 西西 提交于 2019-12-23 04:49:16

问题


I need to find UI Elements within my Windows Desktop WPF application using xpath and Appiums xpath-selector.

It's working fine for "simple" applications but fails for my target application.

My environment is:

OS: Windows 10
Target Application: x86 WPF
Appium Windows Driver: 4.0.0.6 beta
Appium Desktop Application: 1.13.0
Selenium WebDriver: 3.141.0

This is what I am trying:

Once I have fired up my target application by the Appium desktop application, its session window tells me the xpath to UI-elements, such as (also see the screenshots):

xpath:

"/Windows/ToolBar/Tab/TabItem[1]"

Appium Session Window Screenshot:

Microsofts inspect.exe screenshot:

The wired thing now is:

If I am using the xpath-string that appium shows me, in order to find the corresponding UI-Element within this session manager itself (by using the search-feature and selecting the xpath-selector), it's unable to find any elements (see screenshots):

Also, if I am using a trivial xpath-string such as

"//*"

or

"/Window"

it fails as well by not finding any elements.

Here, as a contrast, are the same steps captured by screenshots for the baretail.exe notepad application, for which it works, i.e. where I am able to use the provided xpath-string to correctly find the corresponding UI-Element.

Appium Session Windows:

Microsofts inspect.exe:

Appium Session Window search for UI-Element - query:

Appium Session Window search for UI-Element - result:

Eventually, I need to use this from within a C#-project, for which I am using the following code, but i am getting the same result, which is, not finding any UI-Elements matching my xpath-string.

(I debugged the Appium source so far that I already know that the FindElement-request using the xpath-selecotr is submitted successfully, but the Appium server responds with an empty result set of found UI-Elements.)

AppiumOptions options = new AppiumOptions();

options.AddAdditionalCapability("app", "path/to/my/target/application");
options.AddAdditionalCapability("deviceName", "WindowsPC");
options.AddAdditionalCapability("platformName", "Windows");
options.AddAdditionalCapability("newCommandTimeout", "60000");

session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), options);

Assert.IsNotNull(session);

session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);

string xpath = "/Window/MenuBar/MenuItem[2]"; // valid xpath to an UI-Element
var result = session.FindElementsByXPath(xpath); // successfully returns an empty collection

Anyone, any ideas? Please ...

来源:https://stackoverflow.com/questions/56597995/appium-unable-to-find-ui-elements-using-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!