柏树单击具有SPRC的表中的nth图像

发布于 2025-01-18 14:12:14 字数 959 浏览 1 评论 0原文

我在表中有一个项目列表,每个项目都有一个图像,活动(蓝色)和非活动(黑色),如何对 cypress 进行此查询。

这是表格列表的图像: 输入图片描述在这里

然后这是表的 html 代码: 输入图片此处描述

当展开图像时,它的 src 路径为 /static/images/icon_profile.png 输入图片此处描述

我当前的测试是这样的:

it('Should create a legal form of a Customer profile', ()=>{
    cy.get('th').eq(50).find('img').should('have.attr', 'src', '/static/images/icon_profile.png').first().click()
  })

但是当我运行它时,我收到此错误:

在此处输入图像描述

I have a list of items in the table, each item has an image , active (blue) and not active (black), how do I make this query for cypress.

This is the image of the table list :
enter image description here

Then this is the html code for the table :
enter image description here

When expanded the image is below, it has a src path of /static/images/icon_profile.png
enter image description here

My current test is like this :

it('Should create a legal form of a Customer profile', ()=>{
    cy.get('th').eq(50).find('img').should('have.attr', 'src', '/static/images/icon_profile.png').first().click()
  })

But when I ran it I get this error :

enter image description here

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

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

发布评论

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

评论(2

雪若未夕 2025-01-25 14:12:14

您可以通过组合选择器来更轻松地完成此操作。

cy.get('tr img[src="/static/images/icon_profile.png"]')
  .first()
  .parent('a')  // click the link not the img
  .click()

使用 .eq(50) 运行时确认您拥有正确的索引

cy.get('tr img[src="/static/images/icon_profile.png"]')
  .first()
  .parent('tr')
  .invoke('index')  // which row is it?
  .log()

You can do it more easily by combining selectors

cy.get('tr img[src="/static/images/icon_profile.png"]')
  .first()
  .parent('a')  // click the link not the img
  .click()

To confirm you have the right index when using .eq(50) run

cy.get('tr img[src="/static/images/icon_profile.png"]')
  .first()
  .parent('tr')
  .invoke('index')  // which row is it?
  .log()
撩发小公举 2025-01-25 14:12:14

你可以做这样的事情

cy.get('tr').each(($ele) => {
  if ($ele.attr('src') == '/static/images/icon_profile.png') {
    cy.wrap($ele).parent('a').click()
  }
})

You can do something like this

cy.get('tr').each(($ele) => {
  if ($ele.attr('src') == '/static/images/icon_profile.png') {
    cy.wrap($ele).parent('a').click()
  }
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文