title: How to find the element corresponding to particular object using cypress?
body: <p>I have just started with Cypress and it got my attention. However, when I try to be more specific with my testing I am finding it hard. The page which I am trying to automate has a form which looks like this:</p>
  <pre><code>&lt;form&gt;
     &lt;div class=&quot;mb-3&quot;&gt;
        &lt;div class=&quot;MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth&quot;&gt;
           &lt;label class=&quot;MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated Mui-error Mui-error&quot; data-shrink=&quot;false&quot;&gt;Email address&lt;/label&gt;
           &lt;div class=&quot;MuiInputBase-root MuiInput-root MuiInput-underline Mui-error Mui-error MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl&quot;&gt;&lt;input aria-invalid=&quot;true&quot; name=&quot;email&quot; placeholder=&quot;Enter your email address&quot; type=&quot;email&quot; class=&quot;MuiInputBase-input MuiInput-input&quot; value=&quot;&quot;&gt;&lt;/div&gt;
           &lt;p class=&quot;MuiFormHelperText-root Mui-error&quot;&gt;Please enter a valid email address&lt;/p&gt;
        &lt;/div&gt;
     &lt;/div&gt;
     &lt;div class=&quot;mb-3&quot;&gt;
        &lt;div class=&quot;MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth&quot;&gt;
           &lt;label class=&quot;MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated Mui-error Mui-error&quot; data-shrink=&quot;false&quot;&gt;Password&lt;/label&gt;
           &lt;div class=&quot;MuiInputBase-root MuiInput-root MuiInput-underline Mui-error Mui-error MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl&quot;&gt;&lt;input aria-invalid=&quot;true&quot; name=&quot;password&quot; placeholder=&quot;Enter your password&quot; type=&quot;password&quot; class=&quot;MuiInputBase-input MuiInput-input&quot; value=&quot;&quot;&gt;&lt;/div&gt;
           &lt;p class=&quot;MuiFormHelperText-root Mui-error&quot;&gt;Password should have minimum of 8 chars.&lt;/p&gt;
        &lt;/div&gt;
     &lt;/div&gt;
     &lt;div class=&quot;mb-3&quot;&gt;
        &lt;div class=&quot;MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth&quot;&gt;
           &lt;label class=&quot;MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated&quot; data-shrink=&quot;false&quot;&gt;Confirm password&lt;/label&gt;
           &lt;div class=&quot;MuiInputBase-root MuiInput-root MuiInput-underline MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl&quot;&gt;&lt;input aria-invalid=&quot;false&quot; name=&quot;password_confirm&quot; placeholder=&quot;Confirm password&quot; type=&quot;password&quot; class=&quot;MuiInputBase-input MuiInput-input&quot; value=&quot;&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
     &lt;/div&gt;
     &lt;div class=&quot;form-group pt-2 mb-4&quot;&gt;By clicking the &lt;strong&gt;Create account&lt;/strong&gt; button below you agree to our terms of service and privacy statement.&lt;/div&gt;
     &lt;button class=&quot;MuiButtonBase-root MuiButton-root MuiButton-contained mb-5 MuiButton-containedPrimary MuiButton-containedSizeLarge MuiButton-sizeLarge&quot; tabindex=&quot;0&quot; type=&quot;submit&quot;&gt;&lt;span class=&quot;MuiButton-label&quot;&gt;Create Account&lt;/span&gt;&lt;span class=&quot;MuiTouchRipple-root&quot;&gt;&lt;/span&gt;&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>Here I have error messages associated to 'email' and 'password' fields, both elements in a <p> under respective 's.
  I can validate the error messages by using below statement easily:</p>
  <pre><code>cy.get('p').contains('Please enter a valid email address')
  and
  cy.get('p').contains('Password should have minimum of 8 chars')
  </code></pre>
  <p>But what I want to do is, get the  element and find the child <p> of my div element and then get the text of my <p> element.
  Why I want to do this is to make sure that the error message that I am trying to validate actually corresponds to my test element.</p>
  <p>How can I achieve it?
  Thanks in advance!</p>