1 javascript arrays list cypress
我正在学习 javascript 和 cypress,我需要你的帮助,拜托...我想在页面上找到一个项目,并将该项目添加到购物车。
\n我不明白为什么我在之后没有得到任何答复.find。我在 cypress 上没有收到错误,但它从未添加到购物车中,并且不cy.log显示任何内容。
/// <reference types="Cypress"/>\n\n it ('ContarElementos', () => {\n cy.visit ('https://www.saucedemo.com/v1/inventory.html')\n\n cy.get('.inventory_list >')\n cy.get('.inventory_list >').as ('ProductosPopulares')\n cy.get('@ProductosPopulares').should('have.length', 6)\n })\n\n it ('Agregar elemento "top" al carrito de compra desde la pagina principal', function (){\n cy.visit ('https://www.saucedemo.com/v1/inventory.html')\n\n cy.get('.inventory_list >').as ('ProductosPopulares')\n\n cy.get('@ProductosPopulares')\n .find ('.inventory_item_name')\n .each(($el,index,$list) => {\n if($el.attr('.inventory_item_name') == 'Sauce Labs Onesie'){\n cy.log ('Se encontr\xc3\xb3 lo buscado')\n cy.get ('@ProductosPopulares').eq(index).contains('ADD TO CART').click()\n } \n })\n })\n })\nI know the place that has the item, so if I place it like this, it find appears on the cart, but I need it to work if I dont know the place on the list.\n\nit ('Agregar elemento "top" al carrito de compra desde la pagina principal', function (){\n\n cy.visit ('https://www.saucedemo.com/v1/inventory.html')\n\n cy.get('.inventory_list >').as ('ProductosPopulares')\n\n cy.get('@ProductosPopulares')\n .find ('.inventory_item_name')\n .each(($el,index,$list) => {\n if($el.attr('.inventory_item_name') == 'Sauce Labs Onesie'){\n cy.log ('Se encontr\xc3\xb3 lo buscado')\n \n } \n \n })\n cy.get ('@ProductosPopulares').eq(5).contains('ADD TO CART').click()\n })\nRun Code Online (Sandbox Code Playgroud)\n
文本和属性之间存在混淆,请尝试交换.find()命令和.contains()命令。
像这样的东西:
cy.contains('.inventory_list .inventory_item', 'Sauce Labs Onesie')
.find('button:contains("ADD TO CART")').click()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
147 次 |
| 最近记录: |