如果元素有多个 id 值,如何使用 @FindBy 查找元素 [英] How to find elements with @FindBy if they have multiple id values

查看:31
本文介绍了如果元素有多个 id 值,如何使用 @FindBy 查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的是声明页面元素(移动元素,带有@FindBy 或@AndroidFindBy),其中包含两个可能的 id,这些 id 将根据正在测试的应用程序的版本而变化——我们将有一个 id 用于暂存版本一个用于生产,它们会略有不同(一个在 id 值中间有调试",另一个没有)

What I need is to declare page elements (mobile elements, with @FindBy or @AndroidFindBy) with two possible ids that will change depending on the version of the app that is being tested - we will have one id for the staging version and one for production and they will slightly different (one will have "debug" in the middle of the id value, and the other won't)

这是否可能(通过使用 OR 或任何其他方式)以及如何实现?

Is this possible (by using OR or any other way) and how?

谢谢.

推荐答案

您可以使用注释 @FindAll.例子如下:

You can use the annotation @FindAll. Here is the example:

@FindAll({
        @FindBy(id = "one_id"),
        @FindBy(id = "another_id")
})
WebElement myElement;

参见 文档.

这种方法的优点是您实际上可以组合不同类型的定位器.

The advantage of this approach is that you can actually combine the locators of different types.

这篇关于如果元素有多个 id 值,如何使用 @FindBy 查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆