Is this: cy.get(\'[name=planSelect]\').contains(dummyPlan)
equivalent to this: cy.get(\'[name=planSelect]\').should(\'contain\', dummyPlan)
.contains(selector, content)
is the best selector; it retries
element selection AND allows text matching (not just .class
#id
[attributes]
)
.should()
is just an assertion and only the assertion is retried
(not the element selection)
.should('exist')
is implied unless you specify your own -- this is how they allowed .should('not.exist')
Browsers support XPath 1.0 which is a pretty cool but obscure way to make complex queries based on DOM tree traversal. There's a contains predicate function:
//*[ contains(normalize-space(.), 'The quick brown fox jumped over the lazy dog.') ]
[not(.//*[contains(normalize-space(.), 'The quick brown fox jumped over the lazy dog.') ])]
This searches from root of the document for any node that contains the text and doesn't contain a descendant node which contains the text. You can test it in the console:
$x("//*[contains(normalize-space(.), 'The quick brown fox jumped over the lazy dog.')][not(.//*[contains(normalize-space(.), 'The quick brown fox jumped over the lazy dog.') ])]")