首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过标识同一行中的另一个单元格值来单击行值中的元素

通过标识同一行中的另一个单元格值来单击行值中的元素
EN

Stack Overflow用户
提问于 2019-04-10 15:18:52
回答 2查看 235关注 0票数 2

我必须单击一个元素,该元素在表中的所有行中都是通用的。但问题是,我只想单击某一特定行的元素。我需要的行可以在表中的任何位置。因此,我所需要的就是确定我需要的行,然后单击元素。

添加了我已经尝试过的代码,但失败了。

代码语言:javascript
复制
var ClickEdit = element
    .all(by.cssContainingText('.table-element-row'))
    .filter(function(rowElement){
        return rowElement.element(by.css("td h5")).getText().then(function(text){
            return text.trim() == "Company Created by Test Automation"
        });
    })
    .first()
    .element(by.name('action-menu-trigger')).click();

我需要的是:识别具有'Created by Test Automation‘的行,并在同一行中通过name=action-menu-trigger点击元素。

名称为action-menu-trigger的元素出现在表的所有行中。

代码语言:javascript
复制
<tr _ngcontent-c44="" class="table-element-row mat-row ng-tns-c44-63 ng-star-inserted" mat-row="" role="row">

  <td _ngcontent-c44=""
class="custom-t-user mat-cell cdk-column-responsible mat-column-responsible ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<app-user-profile-logo _ngcontent-c44="" class="ng-tns-c44-63" shape="circle" size="small" _nghost-c18="">
  <div _ngcontent-c18="" aria-describedby="cdk-describedby-message-20" cdk-describedby-host=""
    class="logo logo-size--small logo-shape--circle d-inline-block m-0 mt-2"
    style="touch-action: none; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
    <div _ngcontent-c18="">
      <div _ngcontent-c18="" class="logo-initial ng-star-inserted">RS</div>
      <img _ngcontent-c18="" class="custom-lg-img-pos ng-star-inserted" data-img-type="no-user"
        data-max-retry="4" data-retry="0"
        src="http://studio.images/demo-designer/images/d374d7560002a04eb20878005a53c1d0df18_4.jpg">
    </div>
  </div>
</app-user-profile-logo>
  </td>

  <td _ngcontent-c44="" class="custom-t-act mat-cell cdk-column-name mat-column-name ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h5 _ngcontent-c44="" class="mb-0 pointer" tabindex="0"><b _ngcontent-c44="" class="ng-tns-c44-63">Company
  Created by Test Automation</b>
</h5>
  </td>

  <td _ngcontent-c44="" class="custom-t-act mat-cell cdk-column-owner mat-column-owner ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h5 _ngcontent-c44="" class="mb-0 pointer"><b _ngcontent-c44="" class="ng-tns-c44-63">Robert</b></h5>
  </td>

  <td _ngcontent-c44="" class="custom-t-cat mat-cell cdk-column-type mat-column-type ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h6 _ngcontent-c44="" class="mb-0 opacity-medium">
  <span _ngcontent-c44="" class="ng-tns-c44-63 ng-star-inserted">
  <span _ngcontent-c44="" class="ng-tns-c44-63 ng-star-inserted"> Owner/Operator </span>
  </span>
</h6>
  </td>

  <td _ngcontent-c44="" class="custom-t-cat mat-cell cdk-column-city mat-column-city ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h6 _ngcontent-c44="" class="mb-0 opacity-medium">Dubai</h6>
  </td>

  <td _ngcontent-c44=""
class="custom-t-cat mat-cell cdk-column-country mat-column-country ng-tns-c44-63 ng-star-inserted" mat-cell=""
role="gridcell">
<h6 _ngcontent-c44="" class="mb-0 opacity-medium">United Arab Emirates</h6>
  </td>

  <td _ngcontent-c44=""
class="custom-t-actions mat-cell cdk-column-actions mat-column-actions ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<button _ngcontent-c44="" class="ng-tns-c44-63 mat-icon-button" aria-haspopup="true" mat-icon-button=""
  name="action-menu-trigger">
  <span class="mat-button-wrapper">
    <mat-icon _ngcontent-c44="" class="inv-icon-size--small mat-icon ng-tns-c44-63 mat-icon-no-color"
      role="img" svgicon="inv-ellipsis-h" aria-hidden="true">
      <svg width="100%" height="100%" viewBox="0 0 17 3" version="1.1" xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink" fit="" preserveAspectRatio="xMidYMid meet"
        focusable="false">
        <!-- Generator: sketchtool 51.3 (57544) - http://www.bohemiancoding.com/sketch -->
        <title>E1FE60C0-EF43-4EE7-AF32-E28F60D7C746@1,5x</title>
        <desc>Created with sketchtool.</desc>
        <defs></defs>
        <g id="UX-DESIGNER" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="ui-03list_02--spec--product-type" transform="translate(-1493.000000, -589.000000)"
            fill="#333333">
            <g id="list/product-type-copy-2" transform="translate(255.000000, 547.000000)">
              <g id="Group-10" transform="translate(185.000000, 18.000000)">
                <g id="package/list">
                  <g id="ico/options" transform="translate(1053.000000, 24.000000)">
                    <g id="Group-4">
                      <circle id="Oval" cx="1.5" cy="1.5" r="1.5"></circle>
                      <circle id="Oval-Copy" cx="8.5" cy="1.5" r="1.5"></circle>
                      <circle id="Oval-Copy-2" cx="15.5" cy="1.5" r="1.5"></circle>
                    </g>
                  </g>
                </g>
              </g>
            </g>
          </g>
        </g>
      </svg>
    </mat-icon>
  </span>
  <div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div>
  <div class="mat-button-focus-overlay"></div>
</button>
<mat-menu _ngcontent-c44="" class="ng-tns-c44-63 ng-tns-c9-93" xposition="before">
</mat-menu>
  </td>
</tr>

<tr _ngcontent-c44="" class="table-element-row mat-row ng-tns-c44-63 ng-star-inserted" mat-row="" role="row">
  <td _ngcontent-c44=""
class="custom-t-user mat-cell cdk-column-responsible mat-column-responsible ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<app-user-profile-logo _ngcontent-c44="" class="ng-tns-c44-63" shape="circle" size="small" _nghost-c18="">
  <div _ngcontent-c18="" aria-describedby="cdk-describedby-message-20" cdk-describedby-host=""
    class="logo logo-size--small logo-shape--circle d-inline-block m-0 mt-2"
    style="touch-action: none; user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);">
    <div _ngcontent-c18="">
      <div _ngcontent-c18="" class="logo-initial ng-star-inserted">RS</div>
      <img _ngcontent-c18="" class="custom-lg-img-pos ng-star-inserted" data-img-type="no-user"
        data-max-retry="4" data-retry="0"
        src="http://studio.images/demo-designer/images/d374d7560002a04eb20878005a53c1d0df18_4.jpg">
    </div>
  </div>
</app-user-profile-logo>
  </td>
  <td _ngcontent-c44="" class="custom-t-act mat-cell cdk-column-name mat-column-name ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h5 _ngcontent-c44="" class="mb-0 pointer" tabindex="0"><b _ngcontent-c44="" class="ng-tns-c44-63">Company
  Created by Test Automation</b>
</h5>
  </td>
  <td _ngcontent-c44="" class="custom-t-act mat-cell cdk-column-owner mat-column-owner ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h5 _ngcontent-c44="" class="mb-0 pointer"><b _ngcontent-c44="" class="ng-tns-c44-63">Robert</b></h5>
  </td>
  <td _ngcontent-c44="" class="custom-t-cat mat-cell cdk-column-type mat-column-type ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h6 _ngcontent-c44="" class="mb-0 opacity-medium">
  <span _ngcontent-c44="" class="ng-tns-c44-63 ng-star-inserted">
  <span _ngcontent-c44="" class="ng-tns-c44-63 ng-star-inserted"> Owner/Operator </span>
  </span>
</h6>
  </td>
  <td _ngcontent-c44="" class="custom-t-cat mat-cell cdk-column-city mat-column-city ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<h6 _ngcontent-c44="" class="mb-0 opacity-medium">Dubai</h6>
  </td>
  <td _ngcontent-c44=""
class="custom-t-cat mat-cell cdk-column-country mat-column-country ng-tns-c44-63 ng-star-inserted" mat-cell=""
role="gridcell">
<h6 _ngcontent-c44="" class="mb-0 opacity-medium">United Arab Emirates</h6>
  </td>
  <td _ngcontent-c44=""
class="custom-t-actions mat-cell cdk-column-actions mat-column-actions ng-tns-c44-63 ng-star-inserted"
mat-cell="" role="gridcell">
<button _ngcontent-c44="" class="ng-tns-c44-63 mat-icon-button" aria-haspopup="true" mat-icon-button=""
  name="action-menu-trigger">
  <span class="mat-button-wrapper">
    <mat-icon _ngcontent-c44="" class="inv-icon-size--small mat-icon ng-tns-c44-63 mat-icon-no-color"
      role="img" svgicon="inv-ellipsis-h" aria-hidden="true">
      <svg width="100%" height="100%" viewBox="0 0 17 3" version="1.1" xmlns="http://www.w3.org/2000/svg"
        xmlns:xlink="http://www.w3.org/1999/xlink" fit="" preserveAspectRatio="xMidYMid meet"
        focusable="false">
        <!-- Generator: sketchtool 51.3 (57544) - http://www.bohemiancoding.com/sketch -->
        <title>E1FE60C0-EF43-4EE7-AF32-E28F60D7C746@1,5x</title>
        <desc>Created with sketchtool.</desc>
        <defs></defs>
        <g id="UX-DESIGNER" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
          <g id="ui-03list_02--spec--product-type" transform="translate(-1493.000000, -589.000000)"
            fill="#333333">
            <g id="list/product-type-copy-2" transform="translate(255.000000, 547.000000)">
              <g id="Group-10" transform="translate(185.000000, 18.000000)">
                <g id="package/list">
                  <g id="ico/options" transform="translate(1053.000000, 24.000000)">
                    <g id="Group-4">
                      <circle id="Oval" cx="1.5" cy="1.5" r="1.5"></circle>
                      <circle id="Oval-Copy" cx="8.5" cy="1.5" r="1.5"></circle>
                      <circle id="Oval-Copy-2" cx="15.5" cy="1.5" r="1.5"></circle>
                    </g>
                  </g>
                </g>
              </g>
            </g>
          </g>
        </g>
      </svg>
    </mat-icon>
  </span>
  <div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div>
  <div class="mat-button-focus-overlay"></div>
</button>
<mat-menu _ngcontent-c44="" class="ng-tns-c44-63 ng-tns-c9-93" xposition="before">
</mat-menu>
  </td>
</tr>

代码语言:javascript
复制
<button _ngcontent-c44="" class="ng-tns-c44-63 mat-icon-button" aria-haspopup="true" mat-icon-button="" name="action-menu-trigger"><span class="mat-button-wrapper"><mat-icon _ngcontent-c44="" class="inv-icon-size--small mat-icon ng-tns-c44-63 mat-icon-no-color" role="img" svgicon="inv-ellipsis-h" aria-hidden="true"><svg width="100%" height="100%" viewBox="0 0 17 3" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fit="" preserveAspectRatio="xMidYMid meet" focusable="false">
    <!-- Generator: sketchtool 51.3 (57544) - http://www.bohemiancoding.com/sketch -->
    <title>E1FE60C0-EF43-4EE7-AF32-E28F60D7C746@1,5x</title>
    <desc>Created with sketchtool.</desc>
    <defs></defs>
    <g id="UX-DESIGNER" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="ui-03list_02--spec--product-type" transform="translate(-1493.000000, -589.000000)" fill="#333333">
            <g id="list/product-type-copy-2" transform="translate(255.000000, 547.000000)">
                <g id="Group-10" transform="translate(185.000000, 18.000000)">
                    <g id="package/list">
                        <g id="ico/options" transform="translate(1053.000000, 24.000000)">
                            <g id="Group-4">
                                <circle id="Oval" cx="1.5" cy="1.5" r="1.5"></circle>
                                <circle id="Oval-Copy" cx="8.5" cy="1.5" r="1.5"></circle>
                                <circle id="Oval-Copy-2" cx="15.5" cy="1.5" r="1.5"></circle>
                            </g>
                        </g>
                    </g>
                </g>
            </g>
        </g>
    </g>
</svg></mat-icon></span><div class="mat-button-ripple mat-ripple mat-button-ripple-round" matripple=""></div><div class="mat-button-focus-overlay"></div></button>

EN

回答 2

Stack Overflow用户

发布于 2019-04-10 15:48:08

如果可以使用XPath来选择<button>元素,该元素是包含"Created by Test Automation“文本的元素的后代,请使用以下选择器

代码语言:javascript
复制
//td[contains(., 'Created by Test Automation')]/following-sibling::td//button
票数 1
EN

Stack Overflow用户

发布于 2019-04-10 21:02:02

您可以将搜索文本传递给by.cssContainingText(),如下所示,然后您不需要进行过滤。

代码语言:javascript
复制
element(by.cssContainingText('tr.table-element-row', 'Company Created by Test Automation'))
.element(by.xpath('./..'))
.element(by.css('button[name="action-menu-trigger"]'))
.click()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55606828

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档