testcafe доступ к элементам li

Мне нужна помощь в доступе к элементам li по ссылке ниже.

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

Мои элементы li в файле document.querySelectorAll('#disclaimer+section li')

Я старался,

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');

но я получаю ошибки. Пожалуйста, помогите мне исправить этот код. Мне нужно индивидуально получить доступ к тегам li для их href или внутреннего текста;

1 ответ

Ваш код должен выглядеть так:

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});
Другие вопросы по тегам