使用Xpath选择和断言2个或更多元素 - Selenium C#

时间:2018-03-15 13:16:54

标签: c# selenium xpath selenium-webdriver selenium-chromedriver

所以,我在使用硒来断言一些物品时遇到了麻烦。 我有这些项目,我可以使用Xpath来找到它们:

<tr md-row="" ng-repeat="item in vm.clienteContratoFactory.contratos
  | limitTo: vm.clienteContratoFactory.query.limitePorPagina: vm.clienteContratoFactory.query.inicioEm" class="md-row ng-scope">
  <td md-cell="" ng-style="isMobile() &amp;&amp; {'min-width': '150px'}" class="md-cell ng-binding">PADRÃO - COMUM COM TURMA</td>
  <td md-cell="" class="md-cell ng-binding">14/04/18</td>
  <td md-cell="" class="md-cell ng-binding md-numeric">13/05/18</td>

  <td md-cell="" class="md-cell ng-binding md-numeric">R$0,00</td>

  <td md-cell="" class="md-cell ng-binding md-numeric">R$30,00</td>

  <td md-cell="" class="md-cell">
      <md-chips class="no-shadow ng-isolate-scope" tabindex="-1">      <md-chips-wrap id="_md-chips-wrapper-114" tabindex="-1" ng-keydown="$mdChipsCtrl.chipKeydown($event)" ng-class="{ 'md-focused': $mdChipsCtrl.hasFocus(),                       'md-readonly': !$mdChipsCtrl.ngModelCtrl || $mdChipsCtrl.readonly,                      'md-removable': $mdChipsCtrl.isRemovable() }" aria-setsize="0" class="md-chips md-readonly"><md-chip ng-show="item.status == 'Ativo'" class="tiny verde right ng-scope ng-hide" aria-hidden="true"><span translate="" class="ng-scope">Ativo</span></md-chip><md-chip ng-show="item.status == 'Suspenso'" class="tiny azul right ng-scope ng-hide" aria-hidden="true"><span translate="" class="ng-scope">Suspenso</span></md-chip><md-chip ng-show="item.status == 'Fila'" class="tiny amarelo right ng-scope ng-hide" aria-hidden="true"><span translate="" class="ng-scope">Na fila</span></md-chip><md-chip ng-show="item.status == 'Cancelado'" class="tiny vermelho right ng-scope" aria-hidden="false"><span translate="" class="ng-scope">Cancelado</span></md-chip><md-chip ng-show="item.status == 'Expirado'" class="tiny preto right ng-scope ng-hide" aria-hidden="true"><span translate="" class="ng-scope">Expirado</span></md-chip><md-chip ng-show="item.status == 'Trasferencia'" class="tiny vermelho right ng-scope ng-hide" aria-hidden="true"><span translate="" class="ng-scope">Transferido</span></md-chip>        <!-- ngIf: $mdChipsCtrl.readonly -->        <!-- ngRepeat: $chip in $mdChipsCtrl.items -->        <!-- ngIf: !$mdChipsCtrl.readonly && $mdChipsCtrl.ngModelCtrl -->      </md-chips-wrap></md-chips>
  </td>

  <td md-cell="" class="md-cell">
      <a class="md-icon-button md-button md-ink-ripple" ng-transclude="" ui-sref="app.clientes.clientesCadastros.contrato-detalhe({idClienteContrato: item.idClienteContrato})" href="#/app/W12HOMOLOG/1/clientes/282//contrato-detalhe/1916">
          <md-icon class="material-icons ng-scope" aria-label="Detalhes">
              remove_red_eye

          </md-icon>
      <div class="md-ripple-container"></div></a>
      <!--<div ng-if="item.idFilial != vm.idFilial">
          <span translate>Filial</span>: {{item.idFilial}}
      </div>-->
  </td>

然后我用它来点击,但脚本只需点击第一个tbody列表:

        var contratoExistente = Driver.FindElement(By.XPath("//*[@id='tableHistoricoContratos']/table/tbody/tr/td[1][contains(text(), 'PADRÃO - COMUM COM TURMA')]"))
        //Inicio
        .FindElement(By.XPath(".")).FindElement(By.XPath("//td[2][contains(text(), '14/04/18')]"))
        //Fim
        .FindElement(By.XPath(".")).FindElement(By.XPath("//td[3][contains(text(), '13/05/18')]"))
        //Valor Total
        .FindElement(By.XPath(".")).FindElement(By.XPath("//td[5][contains(text(), 'R$30,00')]"));

    Assert.IsTrue(contratoExistente.Displayed);

    contratoExistente.FindElement(By.XPath(".")).FindElement(By.XPath("//td[7]/a/md-icon")).Click();

有没有办法点击我想要的tr上的正确项目?

0 个答案:

没有答案