Cypress picks up the wrong element?

cypress github
cypress issues
cypress failed because this element is detached from the dom
cypress click first element
cypress click outside of element
cypress guards
cypress wait for element to be visible
cypress click second element

I am trying to find and click this element using Cypress:

<input class="form-control btn btn-primary" type="button" value="Log out">

I have tried several variations, but the closest is this:

 cy.get("input[type='button']").filter('.btn-primary').should('have.value','Log out').click()

So when I run this, I get the following response:

expected [ <input.form-control.btn.btn-primary>, 1 more... ] to have value Log out, but the value was Edit.

Sure, there is a button there called Edit, but it is not the one I want. I have specified what I want with the should('have.value','Log out') clause.

So - why does it insist on trying to use the wrong element & failing?

Update: I finally got this working.

This is the solution I went with in the end:

cy.get("input[type='button']").filter('.btn-primary').eq(1)
    .should('have.value','Log out').then(($btn) => {
          $btn.click()
        })

can you try

cy.get('input').find("[value='Log out']").click()

or

   cy.get("[value='Log out']").click()

Obviously you need your developers to add ids, but I know your situation.

You could also try if there is only one btn-primary

cy.get('.btn-primary').click()

cy.click() yields no error, but wrong element is clicked · Issue #6165 , Pick a username cy.click() yields no error, but wrong element is clicked #6165 I'm having a hard coming up with a minimal example to reproduce the cypress-bot bot added the stage: awaiting response label on Jan 15. You've sent Cypress down a tunnel that is always going to resolve - but resolve to the wrong elements. We should actually write a best practice on this - but you should chain as few commands together as possible. Give Cypress enough information to know what you want instead of chunking it into many little operations as possible.

This was the solution that worked for me:

cy.get("input[type='button']").filter('.btn-primary').eq(1)
.should('have.value','Log out').then(($btn) => {
      $btn.click()
    })

applies blur to wrong element after a series of tests · Issue #610 , Can you check to see if you still have this issue? Our next major release is 1.0.0 and Cypress will be open source then. Here cy is Cypress itself and visit is a Cypress method for browsing to a given path. get instead is a method for selecting elements in the page. With this code we tell Cypress "go grab the form in the page". In a minute we'll see Cypress in action, but first, a bit of configuration! Configuring Cypress

How about to set an unique testID for that button and get it as simple as it can be.

Something like:

data-test-id= "log-out-button" //put that in your button code

and then in Cypress:

cy.get('[data-test-id="log-out-button"]')
  .click()

even though you can set a function to get those testID's more effectively:

Command.Cypress.add('getTestID', (testID) => {
    cy.get(`[data-test-id="${testId}"]`)
})

and now everything you do for getting that button (or every element with testID is: cy.getTestID('log-out-button')

click, Click a DOM element. Syntax.click() .click(options) .click(position) .click(position, options) .click(x, y) .click(x, y, options) Usage Correct Usage cy.get('.btn').click()  Bug when trying to click a div element Hi :) First of all thanks for a awesome service, really enjoy using and testing with cypress 👍 However I have a issue with a test I'm writing, and I'm hoping maybe you can help me :) Current behavio

Error Messages, CypressError: Timed out retrying: Expected to find element: '… A Cached Cypress Binary Could not be found; Incorrect usage of --ci-build-id flag Logging in, viewing runs, and setting up new projects to record requires  A command that yields an element always wraps the element in jQuery. A jQuery object like this always has an array-like structure, even if there is only a single value. This is not something you notice if you stick with pre-made commands but is something that might trip you up if you start going deeper (using .then() , .should() or custom commands).

A History of Navigation on Cypress Bayou and the Lakes, Good lakes those, to run both up and down, or any other way just to unload. from Jefferson was a key element in reportage in the "River Intelligence" column of One day she is up and all right and the next day she is down and all wrong. Cypress is unable to scroll to bottom on React Virtuazlied. Desired behavior: Cypress should be able to scroll to bottom with React Virtualized. Versions. Cypress 3.1.4. Right now I'm doing a proof of concept to see if Cypress is the right choice for our project and we are using React Virtualized to display a list of elements.

The Jazz Cadence of American Culture, That she sleeps with her fists doubled up and ready for action. Down in the Cypress Swamp as he swings his axe he chants: Dat ole black gal, she keeps on but they are misplaced or distorted by the accent falling on the wrong element. 2315445. cypress-io#871 Cypress automatically calls `scrollIntoView` function when `click ()`, `type ()` or something similar is called. This causes problems if there are elements with `position: fixed` This can be fixed by allowing users to send parameters to `scrollIntoView` function.

Comments
  • Did you have any luck with my answer?
  • @Maccurt - have updated the question with the solution that worked.
  • You should make that an answer below. You can answer your own questions. I wonder now if my answer works. I will check it out.
  • I have no control over development. I already have a solution.