简体   繁体   English

UIAStaticText Appium iOS-NodeJS

[英]UIAStaticText Appium iOS - NodeJS

I am currently writing Appium automation tests in NodeJS for iOS. 我目前正在用iOS的NodeJS编写Appium自动化测试。 Although I am having issues with UIAStaticText elements. 虽然我在UIAStaticText元素上遇到问题。 Even though they are visible on screen I constantly get ElementNotFound error. 即使它们在屏幕上可见,我也经常收到ElementNotFound错误。

I am using the XPath for the element displayed in Appium Inspector - it is in the format "//UIAApplication/UIAWindow/UIAStaticText[1]" In the app code the element is a UIALabel. 我将XPath用于Appium Inspector中显示的元素-格式为“ // UIAApplication / UIAWindow / UIAStaticText [1]”。在应用程序代码中,该元素是UIALabel。

I'm trying to get the value of the label but currently unable to getAttribute but it can't find the element. 我正在尝试获取标签的值,但当前无法获取getAttribute但它找不到该元素。

Is there a known limitation with UIAStaticText elements and is there a workaround? UIAStaticText元素是否存在已知限制,并且有解决方法?

Many thanks. 非常感谢。

I'm not sure if you are asking how to get an attribute or how to properly find an element. 我不确定您是否在询问如何获取属性或如何正确查找元素。 I'll assume find an element. 我假设找到一个元素。

I'm not sure of any known issues with UIAStaticText but I would try using the following line 我不确定UIAStaticText是否存在任何已知问题,但是我会尝试使用以下行

driver.findElement(By.xpath("//UIAStaticText[contains(@text, '*Static Text*')]"));

or 要么

driver.findElement(By.xpath("//UIAStaticText[contains(@label, '*label Text*')]"));

This way you are not depending on the previous items within the xpath. 这样,您就不必依赖xpath中的先前项目。 A good way to test if you have a good xpath is to use the copy xml button in the appium inspector and see if your xpath returns a unique item. 测试您是否具有良好的xpath的一种好方法是使用appium检查器中的copy xml按钮,并查看您的xpath是否返回唯一项。

In most cases I have run into the label matches the name or the text. 在大多数情况下,我碰到了与名称或文本匹配的标签。

Hope that answers your question. 希望这能回答你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM