in Education by
When I run my test against that HTML code
foo
bar
Cypress doesn't look beyond the first "div". Here is my test : context('Home', () => { beforeEach(() => { cy.visit('http://example.org') }) it('Find a div', () => { cy.get('div').should('have.attr', 'tester', 'matching') }) }) Si I get the following error : CypressError: Timed out retrying: expected '[
, 1 more... ]' to have attribute 'tester' with the value 'matching', but the value was 'notmatching' So when I put the line : cy.get('div').should('have.attr', 'tester', 'notmatching') It works. What am I doing wrong ? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I think you have to target the second matching element using eq: cy.get('div').eq(1).should('have.attr', 'tester', 'matching') https://docs.cypress.io/api/commands/eq.html#Syntax EDIT: If you want to iterate through them and check each one, you could do this: cy .get('div') .each(($el, index, $list) => { if ($el.attr('tester') === 'matching') { // do something here EDIT 2: If you just want to match the div with that attribute - you can do this: cy.get("div[tester='matching']").should(...

Related questions

0 votes
    A elevator starts with m passengers and stops at n floors (m≤n) . The probability that no two passengers leaves at same ... D. .nCm nm Select the correct answer from above options...
asked Nov 15, 2021 in Education by JackTerrance
0 votes
    My good ladies and gentlemen, I recently had my first go at Worker services in .Net Core 3.1, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    Which of the following stops execution of a thread? (a) Calling SetPriority() method on a Thread object (b ... Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    _________ is an indication that a fatal problem has occurred and execution of the function stops. (a) message (b ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I was running this script to highlight the active page in bold. I had to run jQuery 1.7 for ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    Why a cell stops working after some time ? Select the correct answer from above options...
asked Jan 5, 2022 in Education by JackTerrance
0 votes
    Which of the following stops execution of a thread? (a) Calling SetPriority() method on a Thread object ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    The function stops its execution when it encounters? (a) continue statement (b) break statement (c) goto ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
0 votes
    Why is it essential to get the training of first aid? Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    I'm trying to edit the Original code to get the first p tag from product.description and tried the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any ... in SQL to do this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any ... in SQL to do this? Select the correct answer from above options...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    Could anyone tell me how to get my first AWS job? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    What does the matching score at first layer in recognition hamming network is indicative of? (a) dissimilarity of ... ) none of the mentioned Please answer the above question....
asked Aug 26, 2022 in Education by JackTerrance
...