Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

testcafe accessing li elements

I need help in accessing the li elements in the below link.

https://www.healthdirect.gov.au/medicines/brand/amt,934621000168103/l-arginine-rch

My li elements under document.querySelectorAll('#disclaimer+section li')

I tried,

const seeAlsoElements =  Selector( () => {

            const seeA = document.querySelectorAll('#disclaimer+section li');
            return seeA;

        });

       const seeAlso = await seeAlsoElements();

       actualSeeAlsoFirstLine = seeAlso[0].innerText().split(':');
       aSADAlink = seeAlsoElements[1].child('a').getAttribute('href');
       genericVsBrandArticle = seeAlsoElements[2].getAttribute('href');

but I am getting errors. Please help me in correcting this code. I need to individually access the li tags for their href or inner text;

like image 569
anu Avatar asked Sep 18 '26 03:09

anu


1 Answers

Your code should look like this:

const seeAlsoItems = Selector('main')
    .find('footer')
    .find('section')
    .find('h2').withText('See also')
    .sibling('ul')
    .find('li');

const arginineLink = seeAlsoItems.nth(0).find('a');

await t
    .expect(arginineLink.getAttribute('href'))
    .eql('https://www.healthdirect.../arginine', {timeout: 10000});
like image 77
hdorgeval Avatar answered Sep 22 '26 01:09

hdorgeval



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!