在网上找到定位器(CSS或XPath)如果在一个表中,其具有在列x和y具有一定图案值的行

问题描述 投票:1回答:1

我有一个网站页面使用Selenium测试自动化。有多个行的表。我对点击一排,用柱中,X具有值“就绪”和列中,具有“用户id”和日期“MM / DD / YYYY” Y在一起。顺便说一句,所有的行和单元格是由<div>元素

我能够定位具有一个值“就绪”作为// div[text()='Ready']它返回n个这样的细胞在N行的单元格。也许我可以通过调用获取这些行作为一个列表

WebDriver.getElements("//div[text()='Ready'])

但我有进一步的调查做。像我需要定位在同一行(多个)与“用户ID”字符串和日期“MM / DD / YYYY”在一些其他细胞包括在相同细胞。

这第二部分是什么我不清楚,怎么样!

任何帮助,请!这是我的HTML标记。

<div role="row" row-index="3" row-id="6" comp-id="50" class="ag-row ag-row-odd ag-row-level-0 ag-row--ready ag-row-focus" style="height: 84px; transform: translateY(252px);  ">
  <div tabindex="-1" role="gridcell" comp-id="51" col-id="name" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height ag-cell-no-focus tu-cursor-pointer ag-cell-value ag-column-hover" style="width: 674px; left: 0px; ">
    <ng-component _nghost-c1="" class="center-table">
      <div _ngcontent-c1="" class="extract-name center-table__cell">
        <div _ngcontent-c1="" class="font-bold">PRASAD-FEB-04-215PM-EXTRACT_TEST</div>
        <div _ngcontent-c1="" class="extract-name__description"></div>
      </div>
    </ng-component>
  </div>
  <div tabindex="-1" role="gridcell" comp-id="52" col-id="0" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height font-bold ag-cell-value ag-cell-focus" style="width: 200px; left: 674px; ">**`Ready`**</div>
  <div tabindex="-1" role="gridcell" comp-id="53" col-id="createDate" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height ag-cell-no-focus ag-cell-value" title="2019-02-04 20:19:51.528" style="width: 200px; left: 874px; ">
    <ng-component>**02/04/2019**</ng-component>
  </div>
  <div tabindex="-1" role="gridcell" comp-id="54" col-id="lastRun" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height ag-cell-no-focus tu-cursor-pointer ag-cell-value" style="width: 200px; left: 1074px; ">
    <ng-component _nghost-c2="" class="center-table">
      <!---->
      <div _ngcontent-c2="" class="last-run center-table__cell">
        <div _ngcontent-c2="">**`pnutala`**</div>
        <div _ngcontent-c2="">**`02/04/2019`**</div>
      </div>
    </ng-component>
  </div>
  <div tabindex="-1" role="gridcell" comp-id="55" col-id="1" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height ag-cell-no-focus tu-cursor-pointer ag-cell-value" style="width: 160px; left: 1274px; ">
      <i class="fa fa-copy"></i> <span>Clone</span>
  </div>
  <div tabindex="-1" role="gridcell" comp-id="56" col-id="params" class="ag-cell ag-cell-not-inline-editing ag-cell-with-height ag-cell-no-focus ag-cell-value" style="width: 387px; left: 1434px; ">
    <dhu-preview-list>
      <dhu-preview-info _nghost-c3="" class="center-table">
        <!----><!----><!----><!----><!----><!----><!---->
        <div _ngcontent-c3="" class="center-table__cell">
          <div _ngcontent-c3="">~4,000,000</div>
          <div _ngcontent-c3="">JUN 2016</div>
        </div>
        <!---->
        <div _ngcontent-c3="" class="center-table__cell">
           <button _ngcontent-c3="" cdk-overlay-origin="" class="no-border pull-right" type="button"><i _ngcontent-c3="" aria-hidden="true" class="fa tufa-angle-down"></i></button>
        </div>
        <!---->
      </dhu-preview-info>
    </dhu-preview-list>
  </div>
</div>
selenium selenium-webdriver xpath css-selectors
1个回答
1
投票

这里的XPath的例子包括“就绪”的文字:

//div[@role='row' and ./div[contains(.,'Ready')]]
//div[contains(.,'Ready')]/ancestor::div[@role='row'][1]
//div[@col-id='0' and contains(.,'Ready')]/ancestor::div[@role='row'][1]

lastRun小区的用户名和日期更新:

//div[@role='row' and ./div[contains(.,'Ready')] and ./div[@col-id='lastRun' and contains(.,'pnutala') and contains(.,'02/04/2019')]]

Status是排在第二列和UserId是行,使用列索引做出更为严格,以找到该行的4ND列。

//find row by status and userid
//div[@role='row' and ./div[2][contains(., 'Ready')] and ./div[4][contains(., 'pnutala')]]

// find row by status and userid and date
//div[@role='row' and ./div[2][contains(., 'Ready')] and ./div[4][contains(., 'pnutala')][contains(.,'02/04/2019')]]
© www.soinside.com 2019 - 2024. All rights reserved.