Home > Mobile >  JavaScript - selenium-webdriver - can't find a scroll method
JavaScript - selenium-webdriver - can't find a scroll method

Time:08-19

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

CodePudding user response:

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, e.g.

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

  • Related