如果元素有多个 id 值,如何使用 @FindBy 查找元素

编程入门 行业动态 更新时间:2024-10-28 02:21:27
本文介绍了如果元素有多个 id 值,如何使用 @FindBy 查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要的是声明页面元素(移动元素,带有@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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 18:20:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/919172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何使用   元素   id   FindBy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!