webdriver.execute_script("window") returns nothing

41 views
Skip to first unread message

annk...@gmail.com

unread,
Sep 14, 2018, 6:22:47 AM9/14/18
to ChromeDriver Users
## Meta -
OS:
<!-- Ubuntu 16.04 x64 -->
Selenium Version:
<!-- 3.13 -->
Browser:
<!-- Chrome -->

(Session info: chrome=69.0.3497.92)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.10.0-42-generic x86_64)

Python code to reproduce:
```
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
driver.execute_script("return window")
```
Response:
```
>>> driver.execute_script("return window")
DEBUG - POST http://127.0.0.1:42663/session/7604aae6d0535b100dd0674dce61cc6c/execute {"sessionId": "7604aae6d0535b100dd0674dce61cc6c", "args": [], "script": "return window"}
DEBUG - {"sessionId":"7604aae6d0535b100dd0674dce61cc6c","status":0,"value":[]}
DEBUG - Finished Request
[]
```

**Webdriver.execute_script doesn't want return a window object** from browser-under-test. I receive a NULL instead of dictionary of data.


At the same time 'screen' and 'document' returned as expected
>>> driver.execute_script("return screen")
DEBUG - {"sessionId":"7604aae6d0535b100dd0674dce61cc6c","status":0,"value":{"availHeight":1026,"availLeft":49,"availTop":24,"availWidth":1631,"colorDepth":24,"height":1050,"orientation":{"addEventListener":{},"angle":0,"dispatchEvent":{},"lock":{},"onchange":null,"removeEventListener":{},"type":"landscape-primary","unlock":{}},"pixelDepth":24,"width":1680}}

>>> driver.execute_script("return document")
DEBUG - {"sessionId":"7604aae6d0535b100dd0674dce61cc6c","status":0,"value":{"ELEMENT":"0.2432158247155225-1"}}


For Firefox this issue isn't applicable

Caleb Rouleau

unread,
Sep 14, 2018, 1:18:01 PM9/14/18
to annk...@gmail.com, ChromeDriver Users
HI, is this a new regression in a recent version? i.e. did this at one point work in Chrome and now it doesn't?

Also, why are you needing the information from the window object anyway? It may help to better understand your use case.

--
You received this message because you are subscribed to the Google Groups "ChromeDriver Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromedriver-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Caleb Rouleau
Chrome and Widevine EngProd

annk...@gmail.com

unread,
Sep 14, 2018, 2:09:09 PM9/14/18
to ChromeDriver Users
пятница, 14 сентября 2018 г., 20:18:01 UTC+3 пользователь Caleb Rouleau написал:
It's a new feature for me, so I can't you the webdriver version where it worked.

I'd like access to localStorage and sessionStorage using window object.
I need to do something like this
execute_script("window.sessionStorage.getItem('abc')") to read and write data to sessionStorage

John Chen

unread,
Sep 14, 2018, 2:44:07 PM9/14/18
to annk...@gmail.com, ChromeDriver Users
ChromeDriver is only designed to return simple objects from Chrome to the app. Strings, numbers, and web elements are fine, plus arrays and objects containing those types. Anything beyond that and you'll likely run into problems. You can certainly do execute_script("return window.sessionStorage.getItem('abc')"), but you can't get the whole window object. It's way too complicated.

annk...@gmail.com

unread,
Oct 2, 2018, 9:08:14 AM10/2/18
to ChromeDriver Users
I understood =)

I checked the case when I ask ChromeDriver to return a string/int (not object) it returns it well.


Thank you for your comments

Reply all
Reply to author
Forward
0 new messages