Search code examples
javascriptnode.jsseleniumselenium-webdriver

Selenium-Webdriver, driver.findElement(...).getLocation is not a function, why?


I am trying to call .getLocation() on Selenium element like this code below.

const webdriver  = require('selenium-webdriver');

const driver = new webdriver.Builder()
        .forBrowser('firefox')
        .build();

driver.findElement(webdriver.By.css('.xxxx'))
        .getLocation()
        .then(l => {
           console.log('got a position');
           console.log(l);
        });

But i got

Unhandled promise rejection (rejection id: 1): TypeError: driver.findElement(...).getLocation is not a function

What did i do wrong?. Or do i need to import some other librabry?

Thanks!


Solution

  • There is no getLocation() for WebElement in JavaScript. You have getRect()

    driver.findElement(webdriver.By.css('.xxxx')).getRect()