I have a list of objects on my site that all have 'Add' buttons next to them. When the first 'Add' button is clicked, that object is added and the row disappears and is replaced by the next one down. The object name is the same. I want to .click() three times to add the first three objects in the list, before saving. How can I do this?
I'm aware of .click() to click a single object. I'm also aware of .click ({ multiple: true}) to click all the objects on the page. However, I want it to stop clicking after the third time.
Currently set to click multiple times to add all the objects in the list (which is incorrect):
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.should('exist')
.click({ multiple: true });
Right click all buttons found on the page By default, Cypress will error if you're trying to right click multiple elements. By passing { multiple: true } Cypress will iteratively apply the right click to each element and will also log to the Command Log multiple times.
To find elements by data attribute, query using the attribute selector. cy. get() yields a jQuery object, you can get its attribute by invoking the . attr() method.
For example, to click a hidden element we can use the Cypress command click and pass the option {force : true} as a parameter to it - click({ force: true }). This modifies the hidden characteristics of the hidden element and we can click it.
In summary, { force: true } skips the checks, and it will always fire the event at the desired element.
To hammer click a button you can use this:
for(let n = 0; n < 10; n ++){
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.click()
}
The multiple: true
is used to click several elements, for example to click all buttons on the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With