search

Home  >  Q&A  >  body text

cypress - How to get selection element by selected value?

<p>I'm trying to use Cypress in a Vue project. I have a page that has a table with many rows. Each row has a selection label. This selection label has different options and the current status of each row, such as: "Processing", "Awaiting review", etc. </p> <p>By changing this, there are some conditions; some changing from one state to another are not allowed, some require confirmation, some are OK and show success message. </p> <p>To test this, I have to get the element based on its current value. As I saw in the cypress documentation or on different websites, there is no explanation for this (if possible). </p> <p>So, to be more clear, I want something like this (I know <code>hasValue</code> is not something that exists on cypress): </p> <pre class="brush:php;toolbar:false;">cy.get('select').hasValue('In Process') // or cy.get('select').hasValue(3)</pre> <p>I've tried something like <code>contains</code> but that returns all the text. </p>
P粉034571623P粉034571623481 days ago581

reply all(1)I'll reply

  • P粉460377540

    P粉4603775402023-09-02 00:08:27

    Documentation located hereSelect example,

    There are many display methods, such as using .invoke('val') to extract the value of