调用WebElement列表的单个索引 [英] Call Individual Index of WebElement List

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

问题描述

如果有人需要参考或背景,我的第一个问题是

If anyone needs reference or background here was my first question asked

检索Web元素列表并识别它们

此时此刻我有检索WebElements列表

At this point I have retrieved a list of WebElements

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

此时在我的代码中,我可以使用web元素来调用索引,例如

At this point in my code I can use the web Element to call the index for example

allGridData.get(0).click   

但是列表不是严格的整数,例如,如果我在行级< tr> 访问它将是:

however the list is not strictly integers for example if I access at the row level <tr> it would be:

ctl00_SomeGridData_ucControlList_trgControlList_ctl00__0

但是如果我要调用行内的链接,他们就是表格数据< td> 分成如下所示的div:

but if I were to call a link within row they are table data <td> broken into divs that look like this:

ctl00_SomeGridData_ucControlList_trgControlList_ctl00__ctl04_lbView
ctl00_SomeGridData_ucControlList_trgControlList_ctl00__ctl04_hlTestPlan

或this

ctl00_SomeGridData_ucControlList_trgControlList_ctl00__ctl07_lbView
ctl00_SomeGridData_ucControlList_trgControlList_ctl00__ctl07_hlTestPlan

因为我们所有人bElements以常见的css选择器开头

Since all the WebElements start with a common css selector

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

如何识别作为char值的特定索引(即ctl107)与仅仅整数?

how can identify a specific index that is a char value (ie ctl107) vs just an integer?

推荐答案

假设您需要两个列表,一个用于查看详细信息,另一个用于查看测试计划,则需要 $ (以...结尾):

Assuming you want two lists, one for the View Details and one for the View Test Plans, you need the $ (ends with):

@FindBy(css = "a[id$=lbView]")
List<WebElement> allDetailViewLinks;

@FindBy(css = "a[id$=hlTestPlan]")
List<WebElement> allTestPlanLinks;

但我最好的猜测是你要点击特定行中的链接而不是基于Web元素列表中的索引。例如,基于中的 td 中的文本< tr id =ctl00_SoxMain_ucControlList_trgControlList_ctl00__0class =rgRow>
< td class =rgExpandColvalign =top/>< td valign =top> AL-01< / td>

But my best guess is that you want to click on a link in a specific row rather than based on index in a list of Web Elements. For instance based on the text in the td in <tr id="ctl00_SoxMain_ucControlList_trgControlList_ctl00__0" class="rgRow"> <td class="rgExpandCol" valign="top"/><td valign="top">AL-01</td>.

您需要一种方法来获取td中特定文本的行。

You need a method to get the row with specific text in the td.

WebElement getRow(String specificValue) {
    return driver.findElement(By.xpath("//td[text()='"+specificValue+"']"))
           .findElement(By.xpath(".."));
}

然后你可以制作详细视图和测试计划视图的方法。

Then you can make the methods for detail view and test plan view.

public void openDetailsView(String specificValue) {
    getRow(specificValue)
        .findElement(By.cssSelector("a[id$=lbView]"))
        .click();
}

public void openTestPlanView(String specificValue) {
    getRow(specificValue)
        .findElement(By.cssSelector("a[id$=hlTestPlan]"))
        .click();
}

这篇关于调用WebElement列表的单个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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