如何获取行号,这样行应该包含量角器中的特定文本

How to get row number, such that row should contains a specific text in protractor

我正在使用量角器-黄瓜 framework.I 需要单击 table.Among 所有 table 行中的 'td' 元素,我决定单击一行,这样该行应包含特定文本(假设 "published")。我能够获取该文本,但单击功能是在我需要的 row.So 的其他列上实现的该文本包含的行号,以便使用此行数我将能够单击具有单击 function.Below 的其他列元素是 html 代码之一 table行。

<tr class="K7hAcc QwxBBf" for="iBW8sb0" jsshadow="">
  <td class="XgRaPc AB6Eee RdU54d IRKtVe PLK3Id hhyjHe">
    <content class="zRhise">
      <a class="GRgXff sV" href="https://business.google.com/dashboard/l/16047977676197040292">
        <span class="j5emz">Cavender's Boot City</span><br>
        <span class="D0EYxd">303 NW Loop 410, San Antonio, TX 78216, United States</span>
      </a></content></td>
  <td class="XgRaPc AB6Eee RdU54d IRKtVe">
    <content class="zRhise"><svg viewBox="0 0 24 24" class="zQoJdc P6t5mb"><path d="M0 0h24v24H0z" fill="none"></path><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"></path></svg>
      <span class="StcyZc">Published</span>
    </content></td>
  <td class="XgRaPc AB6Eee RdU54d IRKtVe">
    <content class="zRhise"><div class="ypExpf"></div>
    </content></td>
</tr>

提前致谢。

<ul>
  <li class="pet">Dog</li>
  <li class="pet">Cat</li>
</ul>
Code
// Returns the li for the dog, but not cat.
var dog = element(by.cssContainingText('.pet', 'Dog'));

参考上面的代码。确保你有正确的 CSS 并将 Dog 替换为 Published.

希望对你有帮助

在这种情况下,您可以使用 XPath,例如:

var yourvariable = element(by.xpath('//span[text()="Published"]/ancestor::td'));

PS。这不是 CSS 代码,而是 HTML