单击div类中的span元素

时间:2016-02-22 14:17:38

标签: java selenium-webdriver

我需要从表中选择testdt4。我无法获得显示为Web元素的表项的完整列表。像testdt4一样,我需要找到很多行的表。我可以在List<WebElement>中获取整个列表吗?请帮忙。

<tr class="ng-scope" ng-class="::{warning: !$$cancelLastAction && (entity.$$inProgress || entity.$$hasError)}" ng-repeat="entity in locals.data">
<td class="selectRow">
<!-- ngRepeat: columnDef in locals.gridOptions.columnDefs -->
<td class="ng-scope" ng-repeat="columnDef in locals.gridOptions.columnDefs">
<ci-resource-grid-cell text-limit="textLimit" column="columnDef" data="entity">
<a class="ng-scope" ng-click="openLink(entity)" href="">
<div class="ciTruncate" truncate-limit="150" ci-truncate="columnDef.$$parse(entity)">

<span class="ng-scope">**testdt4**</span>

</div>
</a>
</ci-resource-grid-cell>
</td>
<!-- end ngRepeat: columnDef in locals.gridOptions.columnDefs -->
<td class="ng-scope" ng-repeat="columnDef in locals.gridOptions.columnDefs">

1 个答案:

答案 0 :(得分:0)

  1. 首先 - 你需要一个确定的目标,你要找到什么。正在寻找所有元素或单个元素。如果有多个元素。 [https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/SearchContext.html#findElements-org.openqa.selenium.By-]

  2. 你想找到细胞或行或整个表吗?单元格标签 - td / Row - tr / Table - table。

  3. 使用find元素,下面的xpath搜索将为您提供所有单元格: Xpath表达式:: "//td//span[contains(@class,"ng-scope") and contains(text(),"testdt4")]"

  4. 我在上面给出了// tr,根据需要替换tabletr [pt2] 例如:

    Xpath Expression :: "//tr//span[contains(@class,"ng-scope") and contains(text(),"testdt4")]"

    Xpath Expression :: "//table//span[contains(@class,"ng-scope") and contains(text(),"testdt4")]"

    列出someList = driver.findElement(By.xpath(&#34; Xpath Expression&#34;))

    告诉我你的代码我将修改它::更新你应该使用TD进行单元格。

    By identifierXPath = By.xpath("//tr//span[contains(@class,'ng-scope') and contains(text(),'testdt4')]"); 
    List<WebElement> list_Cells = driver.findElements(identifierXPath);
    System.out.println(list_Cells.size());
    for (WebElement single_Cell : list_Cells){
        System.out.println("Cell Text ::-" + single_Cell.getText().trim());
    }