cypress - How to get selection element by selected value?
P粉034571623
2023-09-01 14:36:33
<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>
Documentation located hereSelect example,
There are many display methods, such as using
.invoke('val')
to extract the value of.