0

(translated using Google translate)

I am trying to loop through the <li> elements of a <ul>, but I cannot make it work.

My HTML:

<ul class="sc-iFMziU>
  <li class="sc-keVrkP"</li>
    <p class="sc-cBdUnI">Parrafo 1</p>
  <li class="sc-keVrkP"</li>
    <p class="sc-cBdUnI">Parrafo 2</p>
</ul>

My Testcafe code:

const ul = Selector('ul')
const li = ul.child('li')

for (let i = 0: i<ul.child('li').length; i++) {
  console.log(ul.child().parent(i))
}

But I can't get it to print anything.


(Original question in Spanish) Estoy intentando recorrer los diferentes li que estan dentro del ul pero no consigo la forma:

HTML:

<ul class="sc-iFMziU>
  <li class="sc-keVrkP"</li>
    <p class="sc-cBdUnI">Parrafo 1</p>
  <li class="sc-keVrkP"</li>
    <p class="sc-cBdUnI">Parrafo 2</p>
</ul>

Con testcafe tengo:

const ul = Selector('ul')
const li = ul.child('li')

for (let i = 0: i<ul.child('li').length; i++) {
  console.log(ul.child().parent(i))
}

Pero no logro que me imprima nada

  • 4
    I suppose questions should be in English here. On the other hand, I can't find any written rule about it in e.g. Tour, or the Help Center. Perhaps it's just an unwritten rule when we all sort of expect people should and will speak English. – pavelsaman Jun 11 at 13:37
  • 3
    Please update your question to English – PDHide Jun 11 at 14:17
  • 1
    @PDHide: thank you for the link. I guess the same goes for SQA here and all other stackexchange communities. It makes sense. So perhaps it's better if questions are in English, but it's not a strict rule. – pavelsaman Jun 11 at 15:24
  • 1
    I have translated using Google translate with minimal editing for readability. The original Spanish is preserved in the question. – Kate Paulk Jun 12 at 12:11
0

There is no length property for selector,

const li = ul.child('li')

returns a selector object. So, instead of length use count and i am not sure what you trying to do by printing parent object , so printing innerText instead

for (let i = 0: i< (await ul.child('li').count); i++) {
  console.log(await ul.child().innerText)
}
| improve this answer | |
  • 1
    Please comment the reason when you down vote , this is really unprofessional – PDHide Jun 11 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.