Reputation: 1545
I'm having a problem with my array. I can't find a specific piece of text even though I've done an algortithmn
Click this link for the video.
I'm getting 200 status for everything, which is perfect. However, when I try to find a specific item (cashews) I am getting an error message.
Here is code:
/// <reference types="Cypress" />
describe('My first test suite', function()
{
//all tests cases go inside of this area
it('Open web page', function() {
cy.visit("https://rahulshettyacademy.com/seleniumPractise/#/")
cy.wait(2000)
cy.get('.search-keyword').type('ca')
cy.get('.product:visible').should('have.length',4)
//parent child elements
cy.get('.products').find('.product').should('have.length',4)
cy.get('.products').find('.product').eq(2).contains('ADD TO CART').click()
//iterate over an array of ojbects using using each
cy.get('.products').find('.product').each(($e1, index, $list)=> {
const textVeg=$e1.find('h4.product-name').text()
if(textVeg.includes('Cashews'))
{
$e1.find.contains('ADD TO CART').click()
//$e1.find('button')
}
})
H
})//end of my first test case
Here is the text from the cypress log file:
TypeError: $e1.find.contains is not a function
What did I do wrong in this algorithm?
Upvotes: 0
Views: 1513
Reputation: 510
You can use cypress command wrap to replace
$e1.find.contains('ADD TO CART').click()
with
cy.wrap($e1).contains('ADD TO CART').click()
Upvotes: 1