Skip to content Skip to sidebar Skip to footer

Window Object From Selenium Webdriver Is Empty Array

I'm trying to get the window object from a Selenium instance. I have the following code: driver.executeScript(() => { return window; }) .then(res => { console.log(res

Solution 1:

Following the document of selenium, https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/JavascriptExecutor.html, driver.executeScript() only return below types of value:

  1. For an HTML element, this method returns a WebElement
  2. For a decimal, a Double is returned
  3. For a non-decimal number, a Long is returned
  4. For a boolean, a Boolean is returned
  5. For all other cases, a String is returned.
  6. For an array, return a List with each object, following the rules above. We support nested lists.
  7. For a map, return a Map with values following the rules above. Unless the value is null or there is no return value, in which null is returned

Which means it can't return window.

Instead of returning window object, I suggest to put all your javascript logic inside the executeScript method, then return any type of value as above. Then use that value in your code for other logic.

Post a Comment for "Window Object From Selenium Webdriver Is Empty Array"