我如何检查 table 中的元素并单击它所在行的元素?

How can i check an element in a table and click on an element of it's row?

关于这个table我有几个条目(在下面的html下面,我只会放相关的条目)。如果该条目在“内容”列中包含文件夹,我需要 select 在垃圾列下方添加一个按钮

<table _ngcontent-sxv-c238="" class="ui small compact selectable striped celled table fix-table unstackable" style="border-top: 0;">
  <thead _ngcontent-sxv-c238="" class="no_mobile_small">
    <tr _ngcontent-sxv-c238="">
      <th _ngcontent-sxv-c238="" class="noselect"><span _ngcontent-sxv-c238="">Content</span>
        <!---->
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect pointer"><span _ngcontent-sxv-c238="">Name</span><i _ngcontent-sxv-c238="" class="float-right icon angle down"></i>
        <!---->
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect pointer"><span _ngcontent-sxv-c238="">Date</span>
        <!----><i _ngcontent-sxv-c238="" class="float-right icon angle up"></i>
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect no_mobile status-column"><span _ngcontent-sxv-c238="">Status</span>
        <!---->
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect"><span _ngcontent-sxv-c238="">Move</span>
        <!---->
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect no_mobile"><span _ngcontent-sxv-c238="">Trash</span>
        <!---->
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect no_mobile"><span _ngcontent-sxv-c238="">Settings</span>
        <!---->
        <!---->
      </th>
      <!---->
      <th _ngcontent-sxv-c238="" class="noselect no_mobile"><span _ngcontent-sxv-c238="">Publish</span>
        <!---->
        <!---->
      </th>
      <!---->
      <!---->
      <th _ngcontent-sxv-c238="" width="38" class="no_mobile"><input _ngcontent-sxv-c238="" id="title-up-all" name="title-up-all" type="checkbox" class="ng-untouched ng-pristine ng-valid"><label _ngcontent-sxv-c238="" for="title-up-all" id="title-up-label-all" style="height: 14px; line-height: 14px; padding-left: 18px; top: -2px;"></label></th>
      <!---->
    </tr>
  </thead>
  <tbody _ngcontent-sxv-c238="">
    <!---->
    <tr _ngcontent-sxv-c238="">
      <td _ngcontent-sxv-c238="" class="collapsing"><i _ngcontent-sxv-c238="" class="ms-icon iconms-folder02 margin-right-icon"></i> Folder </td>
      <td _ngcontent-sxv-c238="">
        <div _ngcontent-sxv-c238="" class="left" style="width: 70%;"><span _ngcontent-sxv-c238="" class="s-truncate">Automation Folder</span></div>
        <div _ngcontent-sxv-c238="" class="left" style="width: 30%;"><span _ngcontent-sxv-c238="" class="encoding-span truncate" style="margin-left: 5px; max-width: calc(50% - 5px);" title="Live Encoding Profile: Inherit"><a _ngcontent-sxv-c238="" class="ui label right encoding-label"><!----><i _ngcontent-sxv-c238="" class="ms-icon iconms-live left e-icon"></i><span _ngcontent-sxv-c238="" title="Inherit from folder and then property" class="truncate encoding-tile">Inherit</span>
          <!---->
          <!---->
          </a>
          </span><span _ngcontent-sxv-c238="" class="encoding-span truncate"  class="ui label right encoding-label"><!----><i _ngcontent-sxv-c238="" class="ms-icon iconms-video left e-icon"></i><span _ngcontent-sxv-c238="" 
          <!---->
          <!---->
          </a>
          </span>
        </div>
      </td>
      <td _ngcontent-sxv-c238="" class="collapsing">12/May/21 14:47</td>
      <td _ngcontent-sxv-c238="" width="70" class="no_mobile"></td>
      <td _ngcontent-sxv-c238="" width="70" title="Move" class="table_button center-align move_mobile no_mobile_small"><i _ngcontent-sxv-c238="" class="ms-icon iconms-folder02"></i></td>
      <td _ngcontent-sxv-c238="" width="70" title="Trash" class="table_button center-align red-text no_mobile"><i _ngcontent-sxv-c238="" class="ms-icon iconms-remove"></i></td>
      <!---->
      <!---->
      <!---->
      <td _ngcontent-sxv-c238="" width="70" title="Settings" class="table_button center-align no_mobile"><i _ngcontent-sxv-c238="" class="ms-icon iconms-settings"></i></td>
      <td _ngcontent-sxv-c238="" class="collapsing no_mobile"></td>
      <td _ngcontent-sxv-c238="" width="38" class="no_mobile"><input _ngcontent-sxv-c238="" type="checkbox" id="select-697a41fc-6555-40e4-9973-ff9312e8e9c6" class="ng-untouched ng-pristine ng-valid"><label _ngcontent-sxv-c238="" style="height: 14px; line-height: 14px; padding-left: 18px; top: -2px;" for="select-697a41fc-6555-40e4-9973-ff9312e8e9c6"></label></td>
      <!---->
    
  </tbody>
</table>

希望该片段足够清晰。在代码段中,在垃圾栏下看不到任何选项,但它有一个按钮,如果单击该按钮,将删除 table.

上的条目

如何通过检查行是否包含内容列中的“文件夹”来执行操作?我希望包含该文件夹的所有列都发生这种情况。我正在使用硒和 c#

基于文件夹,您可以尝试使用以下 xpath 来单击垃圾按钮:

//span[text()='Automation Folder']/../../following-sibling::td[@Title='Trash']

如下所示:

driver.FindElement(By.XPath("//span[text()='Automation Folder']/../../following-sibling::td[@Title='Trash']")).Click();
List<WebElement> tableRows = driver.FindElements(By.XPath(".//table[@class='ui small compact selectable striped celled table fix-table unstackable']/tbody/tr"));
 for(WebElement e: tableRows) {
 if(e.findElement(By.TagName("td")).getAttribute("innerText").contentEquals("Folder")) {
                e.findElement(By.XPath(".//following-sibling::td/input[contains(@id,'select')]")).click();
            }
 }