lundi 21 décembre 2020

Find element within element

I am trying to find an element within a specific element.

My HTML structure is like this:

<div>
     <label>test</label>
     <div>
          <a>testlink</a>
          <input type='text'></input>
          <textarea></textarea>
     </div>
</div>

I have the label based on its text, and I am trying to get the input under its sibling. I was first thinking of hardcoding it, but then noticed we sometimes have an extra layer under the sibling div, like this.

<div>
     <label>test</label>
     <div>
          <div>
              <a>testlink</a>
              <input type='text'></input>
              <textarea></textarea>
          </div>
     </div>
</div>

What I have tried is:

const labelElement = await Selector('label').withText('test')
const inputField = labelElement.sibling('div').find('input').withAttribute('type', 'text')

Problem is that I am getting back all inputs back on the page, not only this one. I guess that is what find does.

Is there any way to only get my required input?

Aucun commentaire:

Enregistrer un commentaire