Search code examples
javascriptseleniumgeckodriverselenium-firefoxdriver

driver.manage(...).window(...).getSize is not a function in selenium


I'm writing a selenium test for a webpage. I just want to get height of webpage.

Take a look at the code below. It uses geckodriver which is a firefox webdriver.

const { Builder, By } = require("selenium-webdriver");
const { writeFile } = require("fs");

async function pageLoad() {
  let driver = await new Builder().forBrowser("firefox").build();

  try {
    await driver.get("http://example.com/");
    const size = await driver.manage().window().getSize();
    console.log(size);
  } catch (err) {
    console.log(err.message);
  } finally {
    await driver.quit();
  }
}

This code generates below error driver.manage(...).window(...).getSize is not a function

However, I've seen in other code people are using getSize without any problem. I've searched everywhere and this is my last option posting on stackoverflow.

I'm using MacOS Catalina and Visual studio Code. I'm a pretty good web developer with strong grasp on javascript. However, I'm new to selenium.


Solution

  • I was able to proceed with getRect instead of getSize.

    const size = await driver.manage().window().getRect();
    

    However, one thing that still bothers me is why the output of below two lines differ?

    await driver.executeScript("return window.screen.height");
    
    await window.getRect().height;