(intermediate value).findElement is not a function

346 Views Asked by At

Hi I'm having an issue with a cookie popup which Im trying to either click on or disable somehow as I think it is affecting the output of my Axe accessibility tests. What would be the best approach? Currently I'm just trying to click on it but getting an error (intermediate value).findelement is not a function. Ideally I'd want to stop the pop up appearing when selenium fires up chrome.

const AxeBuilder = require('@axe-core/webdriverjs');
const WebDriver = require('selenium-webdriver');
const {By} = require('selenium-webdriver');

const driver = new WebDriver.Builder().forBrowser('chrome').build();

driver.get('mysite').then( () => {
    new AxeBuilder(driver)

        .findElement(By.id('accept')).click()
        .analyze((err, results) => {
        if (err) {
            // Handle error somehow
        }
        console.log(results.violations);
    });
});
1

There are 1 best solutions below

0
On

Have you defined findElement() in AxeBuilder class? Here, you are creating an object of AxeBuilder class by passing driver as constructor parameter and on that object you are calling findElement(). If you have defined findElement in AxeBuilder class, then only it is accessible. Otherwise, we will get not a function error. If you need to find an element in 'mysite', use driver.findElement() instead of 'new AxeBuilder(driver).findElement()' and click on it.