appium - NativeScript-Dev-Appium : UIElement.text() / UIElement.getAttribute("value") 返回自动化文本而不是显示的文本
问题描述
我正在使用 NativeScript-Dev-Appium@5.0.0 并希望检查标签上显示的文本。我将automationText属性分配给并使用Driver.findElementByAccessibilityId(automationTextValue)来获取元素。找到了该元素,但是当我尝试对其使用 UIElement.text() / UIElement.getAttribute("value") 时,它会返回automationText 属性的值,而不是实际显示的文本。有没有其他方法可以做到,因为我找不到。
解决方案
不幸的是,这是 NativeScript 本身的限制,因为当使用automationText 属性时,它将设置元素的所有属性,如值、名称、标签等。我建议您将相同的文本设置为automationText 属性,然后您可以访问或使用以下方法测试元素:
- 使用 XPath:
const el = await driver.findElementByXPath("//*[@name=\"My automation text\"]");
- 仅适用于安卓
const el = await driver.findElementByText("My automation text");
const text = await el.getAttribute("text");
- 使用 imageVerification 类型,例如:
await driver.compareRectangle
await driver.compareElement
await driver.compareScreen
这非常方便,但这里的缺点是这在某些时候需要更高的维护。
推荐阅读
- machine-learning - XGBoost - scale_pos_weight 和 class_weights 之间的区别
- python - 是否可以使用 Selenium 获取页面源,然后使用 lxml 通过 xpath 抓取数据?
- heroku - 如何使用 Netlify 和 Heroku 实现 NameCheap DNS
- ansible - Ansible - 如果不满足条件,如何跳过注册变量
- azure - Azure Function App 是否同时运行多个实例?
- c# - 如何将内容链接文件复制到项目目录而不会导致重复
- javascript - 正则表达式匹配文件夹内容的互补子组(webpack 供应商捆绑包)
- python - 查找参考角度的最有效 Python 代码?
- ios - Swift - 通过多个类连接内容数据
- elasticsearch - ElasticSearch:使用Query获取单个文档排名