如何单击柏树在特定文本前面的编辑​​按钮

发布于 2025-02-11 22:07:47 字数 1389 浏览 0 评论 0原文

我想单击第三列中是否在第三列中找到的编辑按钮(是的,也有botton )

element

I was using below code in test case but didn't work

).contains('yes')。在(()=> { cy.get('。btn.btn-xs.btn-edit')。click() })) 或

`cy.get(':nth-​​child(6)')。包含('yes')。查找(button).eq(1).click()

html表结构

    <tr role="row" class="even">
<td class="sorting_1">
<a href="http://192.168.0.1:8080/details">abc</a>
</td>
<td>xyz</td>
<td>aws</td>
<td>No</td>
<td>No</td>
<td>"Yes"
<button data-role="remove" id="support_22_abc" class="btn btn-rejecttxt" onclick="deletevm(this,'3','3:5659','22','abc','22_abc','284')"><i class="fa fa-times-circle" data-original-title="Remove Mapping" data-toggle="tooltip"></i></button></td>
<td>No</td>
<td>
<div class="btn-group">
<a href="http://192.168.0.1:8080/edit">
<button class="btn btn-xs btn-edit">
<i class="fa fa-pencil" data-original-title="Edit/Update row data" data-toggle="tooltip" data-placement="top"></i></button></a>
 </div></td></tr>

I want to click on the edit button in front of if found Yes in the third column(Yes is also have botton)

element

I was using below code in test case but didn't work

`cy.get(':nth-child(6)').contains('Yes').within(() => {
cy.get('.btn.btn-xs.btn-edit').click()
})
or

`cy.get(':nth-child(6)').contains('Yes').find(button).eq(1).click()

HTML Table Structure

    <tr role="row" class="even">
<td class="sorting_1">
<a href="http://192.168.0.1:8080/details">abc</a>
</td>
<td>xyz</td>
<td>aws</td>
<td>No</td>
<td>No</td>
<td>"Yes"
<button data-role="remove" id="support_22_abc" class="btn btn-rejecttxt" onclick="deletevm(this,'3','3:5659','22','abc','22_abc','284')"><i class="fa fa-times-circle" data-original-title="Remove Mapping" data-toggle="tooltip"></i></button></td>
<td>No</td>
<td>
<div class="btn-group">
<a href="http://192.168.0.1:8080/edit">
<button class="btn btn-xs btn-edit">
<i class="fa fa-pencil" data-original-title="Edit/Update row data" data-toggle="tooltip" data-placement="top"></i></button></a>
 </div></td></tr>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

塔塔猫 2025-02-18 22:07:47

如果我正确阅读它,则需要第三&lt; td&gt;带有“是”的。

不确定什么:nth-​​child(6)正在选择,但请尝试

cy.contains('td', 'Yes')
  .siblings()
  .eq(6)            // 6th sibling
  .find('button.btn.btn-xs.btn-edit')
  .click()

If I'm reading it correctly, you want the 3rd <td> after the one with "Yes ".

Not sure what :nth-child(6) is selecting, but try this

cy.contains('td', 'Yes')
  .siblings()
  .eq(6)            // 6th sibling
  .find('button.btn.btn-xs.btn-edit')
  .click()
东走西顾 2025-02-18 22:07:47

假设.btn.btn-xs.btn-edit是编辑按钮的正确选择器。您可以直接使用eq命令单击第三行上的编辑按钮。

cy.get('.btn.btn-xs.btn-edit').eq(2).click()

根据可用信息,我想到了。在这里,我们首先浏览所有tr,然后在中使用我们正在范围内范围内范围内的下一个命令。现在,使用eq(5),我们正在搜索按钮,如果我们找到了它,则单击“编辑”按钮。

cy.get('tr').each(($ele) => {
  //Loop through all tr
  cy.wrap($ele).within(() => {
    //scope the next commands within the same tr
    cy.get('td')
      .eq(5)
      .invoke('text')
      .then((text) => {
        //here eq(5) gets the sixth td element in the row
        if (text.includes('Yes')) {
          cy.get('.btn.btn-xs.btn-edit').click()
        }
      })
  })
})

Assuming .btn.btn-xs.btn-edit is the correct selector for edit button. You can directly use the eq command to click the edit button on the third row.

cy.get('.btn.btn-xs.btn-edit').eq(2).click()

Based on the available info, I came up with this. Here we are looping through the all the tr first and then using within we are scoping the next commands inside the same tr. Now using eq(5) we are searching for the Yes button, and if we found the it, then we click the Edit button.

cy.get('tr').each(($ele) => {
  //Loop through all tr
  cy.wrap($ele).within(() => {
    //scope the next commands within the same tr
    cy.get('td')
      .eq(5)
      .invoke('text')
      .then((text) => {
        //here eq(5) gets the sixth td element in the row
        if (text.includes('Yes')) {
          cy.get('.btn.btn-xs.btn-edit').click()
        }
      })
  })
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文