Smh
Smh

Reputation: 137

Need to click on div to automate in cypress

How can I click in div to automate in cypress?

Any help would be appreciated. Thanks

Upvotes: -2

Views: 209

Answers (3)

jjhelguero
jjhelguero

Reputation: 2571

Since this is button appears in a modal, you'll want search within the modal DOM element so you grab the correct one and not another one that exists in the DOM.

We will us the powerful .contains() with a regex as an argument since adding a selector could make it more brittle.

NOTE: I don't see html for your modal so I will use a dummy selector for it in the example below.

// made up modal selector
cy.get('.modal')
  // always good to assert the modal should be visible
  .should('be.visible')
  .contains(/upload in this folder/i)
  // make sure it is visible before clicking
  .should('be.visible')
  .click()

Upvotes: 0

Pablo
Pablo

Reputation: 350

You can select by the text of the button,

cy.contains('Upload in this folder').click()

Upvotes: 3

Alapan Das
Alapan Das

Reputation: 18650

You can use a combination of selector and inner text with contains for this.

cy.contains('div', 'Upload in this folder').click()

Upvotes: 0

Related Questions