найти веб-локатор (css или xpath), если строка в таблице имеет значения с определенным шаблоном в столбцах x и y - PullRequest
0 голосов
/ 11 февраля 2019

У меня есть страница для тестирования автоматизации с использованием Selenium.Есть таблица с несколькими строками.Мне интересно щелкнуть строку со столбцом, где x имеет значение «Готов» и столбец, а y - «userId» и дата «mm / dd / yyyy».Кстати, все строки и ячейки состоят из <div> элементов

. Я могу найти ячейку со значением «Ready» как // div[text()='Ready'], которая возвращает n таких ячеек в N строках.Вероятно, я могу получить эти строки в виде списка, вызвав

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

Но мне нужно сделать еще один запрос.Как и мне нужно найти какую-то другую ячейку в той же строке (ях) со строкой 'user 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>

1 Ответ

0 голосов
/ 11 февраля 2019

Здесь примеры 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 - это четвертый столбец в строке, используйте индекс столбца, чтобы найти строку более строго.

//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')]]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...