V
V
Vladimir2021-09-09 21:59:41
Node.js
Vladimir, 2021-09-09 21:59:41

Why doesn't the click function even see the prototype of the parent's function?

Hello. I'm trying to pass the index of the clickable element to the click function of the nightmare package . But it ignores variables, constants, arrays, the prototype of the function in which it is located, and I have no idea why at all. Please tell me how this can be solved.

function getPage(url, proxy) {
    const nightmare = Nightmare({
        show: true,
        switches: {
            'proxy-server': proxy[Math.floor(Math.random() * proxy.length)],
            'ignore-certificate-errors': false
        },
    });

    return nightmare
        .authentication('irp1010848', 'UT2092lpfs')
        .goto(url)
        .wait('.hot-list-container ul li')
        .evaluate(() => {
            const data = [...document.querySelectorAll('.hot-list-container ul li')];
            return data.map(el => el.innerHTML).map((el, i) => {
                return {
                    el: el,
                    status: el.split('').join('').indexOf('DYDX') !== -1 ? 0 : 1,
                    index: i+1
                }
            });
        })
        .click(`.hot-list-container ul li:nth-child(${/* Сюда пытаюсь передать, но безуспешно */}) a`)
        .catch(err => console.log(err))
}


Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chipekwe, 2021-09-10
@HistoryART

You can only take the return value from .evaluate()through .then(), that is: . Google suggested that the problem can be solved in the following way: - Make a click (normal) inside on the desired element. - Hang the selector on the desired element through and make a click already without calculations. .evaluate().then((data => nightmare.click(''))
.evaluate()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question