检索WebElement列表并识别它们 [英] Retrieving a list of WebElements and Identifying them

查看:130
本文介绍了检索WebElement列表并识别它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以识别WebElement名称并将其分配给WebElement列表?例如,使用以下约定:W

Is there a way to Identify and assign WebElement Names to a list of WebElements? For example using the following convention:W

@FindBy(xpath="")
WebElement listFirstObject;

@FindBy(xpath="")
WebElement listSecondObject;

如果这是一个基本问题,请原谅我,但是对于许多测试人员来说,这似乎是很常见的情况,因为许多应用程序都有具有相同名称的对象列表.就我而言,我的控制列表中包含700多个对象,并且能够编写一种迭代方法来捕获并从列表中单独创建每个常见WebElement会很高兴.

Forgive me if this is an elementary question, but it seems like it would be a pretty common scenario for any tester as many applications have lists of objects with common names. In my case I have a control list with well over 700 objects and it would be nice to be able to write some iterative method to capture and individually create each common WebElement from the list.

**我已对问题进行了更新以进一步阐明**接受完整的信息对我来说是全新的,因此在尝试理解其背后的逻辑时,请具体说明答案.

** I have made Updates to my question for further clarification** Taking an entire grid of info is completely new to me so please be specific with the answers as I am trying to understand the logic behind it.

所以我要查找的元素是网格数据,例如,我已经成功捕获了整个网格

So I have elements I am looking for are Grid Data, I have successfully captured the entire Grid, for example

@FindBy(id="ctl00_SomeGridData_ucControlList_trgControlList_ctl00")
List<WebElement> someGridData;

如果我要逐个捕获网格中的每个新添加内容,它将看起来像这样:

If I were to individually capture each new addition to the grid it would look as such:

@FindBy(id="ctl00_SomeGridData_ucControlList_trgControlList_ctl00__0")
WebElement someGridObj1;

@FindBy(id="ctl00_SomeGridData_ucControlList_trgControlList_ctl00__1")
WebElement someGridObj2;

@FindBy(id="ctl00_SomeGridData_ucControlList_trgControlList_ctl00__2")
WebElement someGridObj3;

您可以看到每个单独的网格元素都以"__#"结尾.显然,这是一个无限列表,我无法单独捕获每个WebElement并分配用于测试的WebElement值.我要问的是如何捕获整个列表,然后是否需要稍后再调用单个WebElement来测试如何做到这一点?我希望这可以澄清,并感谢您阅读.

As you can see each individual grid element ends with "__#" Obviously this is an infinite list and I cannot capture every WebElement individually and assign a WebElement value to use for testing. What I am trying to ask is how do I capture this entire list and then if i need to call an individual WebElement later to test how do I do so? I hope this clarifies and thanks for reading.

推荐答案

好,现在,您的问题已编辑完毕,您很想知道什么.假设网格数据位于td元素中,则可以执行以下操作.

Ok, now that have edited your question, it's clear what you want to know. Assuming your grid data is in td elements, you can do the following.

@FindBy(css = "td[id^=ctl00_SomeGridData_ucControlList_trgControlList_ctl00__]")
List<WebElement> allGridData;

通过使用^(表示开头),您可以收集所有ID以ctl00_SomeGridData_ucControlList_trgControlList_ctl00__开头的td元素.

By using the ^ (which means starts with) you collect all the td elements that have an id starting with ctl00_SomeGridData_ucControlList_trgControlList_ctl00__.

这篇关于检索WebElement列表并识别它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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