简体   繁体   中英

JavaScript - selenium-webdriver - can't find a scroll method

On the page https://www.ameublement.com/showroom , I go to each brand but after 5-7 brands, the script can't go further because it needs to scroll the page. This is the error:

ElementClickInterceptedError: element click intercepted: Element is not clickable at point (389, 539). Other element would receive the click: <span...

This is my code:

let swd = require("selenium-webdriver");
let browser = new swd.Builder();
let tab = browser.setChromeOptions().forBrowser("chrome").build();

async function main() {

    await tab.get("https://www.ameublement.com/showroom");

    // PAGE BRAND
    let brands = await tab.findElements(
        swd.By.css(".col-6.col-lg-12.card-img")
    );

    for (let e of brands) {
        console.log('go to page of a brand')
        await e.click()

        tab.sleep(300);

        // GO BACK
        tab.navigate().back()

        // await tab.executeScript("arguments[0].scrollIntoView();", e);
        // tab.getElementByClassName(e).scrollIntoView();

    };
}

I tried:

// await tab.executeScript("arguments[0].scrollIntoView();", e);

then I tried:

// tab.getElementByClassName(e).scrollIntoView();

The second one throw this error:

TypeError: tab.getElementByClassName is not a function

That's because tab is an instance of ThenableWebDriver which has no such function. Please see the link for documentation.

What you could do instead is use simple javascript to scroll, eg

await tab.executeScript("window.scrollBy(0,1000)");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM