selenium: [š Bug]: Message KeyError 'width' while trying to get_window_size() does not provide detailed information
What happened?
So from the userās point of view, it is not clear on which side the error is, the webdriver itself or the remote web server.
How can we reproduce the issue?
It is hard to reproduce, but the remote web server used for the remote webdriver should be unreliable and return an error, as shown in the screenshot. In my case, it was BrowserStack Automate.
As requested in the comment: https://github.com/aikfiend/python-selenium-browserstack/tree/get-window-size-key-error
Please note that the code of the test provided does not reproduce the issue in 100% of cases, as the issue itself reproduces from time to time, depending on a remote web server. You may require hundreds or more retries.
In the period from 2025-03-11 to 2025-04-21, I was able to catch it 20 times running tests in 24/7 mode in Browserstack Automate. Commonly, it failed in Chrome and Safari on mobile devices.
Relevant log output
Let the sentry speak for itself
Operating System
Any
Selenium version
4.31.0 (trunk)
What are the browser(s) and version(s) where you see this issue?
Any
What are the browser driver(s) and version(s) where you see this issue?
Any
Are you using Selenium Grid?
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 18 (11 by maintainers)
Commits related to this issue
- [py] Add detailed error message if KeyError thrown in get_window_size and get_window_position (#15503) — committed to aikfiend/selenium by aikfiend 2 years ago
- [py] Add detailed error message if KeyError thrown in get_window_size and get_window_position (#15503) — committed to aikfiend/selenium by aikfiend 2 years ago
@aikfiend
Same here.
Your reproduction code requires Browserstack credentials. I donāt work for Browserstack⦠Iāve never used Browserstack⦠I know nothing about Browserstack⦠I canāt run your code. All I am asking for is a simple reproducible example that I can run. If you canāt provide that, I would at least need logs to look at. I donāt fully understand the issue you are having, so I canāt fix it.
If you want to provide a fix, I will review your code. Otherwise, I donāt like the tone of your complaints and will not be looking further into this⦠maybe somebody else will.
Oh flashback⦠When I started using Selenium/.NET within Browserstack as a browser provider, I developed simple test. But I didnāt put authentication token for Browserstack in my test. What, do you think, happened?.. Test was green!!! I am not kidding, it was literally green, meaning it successfully launched remote browser and navigated to website. I sniffed traffic, and observed that BS responded properly with Unauthenticated status, but for selenium it is not important.
Then I went through Selenium source code and observed, that bindings (probably all) donāt even validate HTTP Response Status Code. Surprise!
https://github.com/SeleniumHQ/selenium/pull/10807 - this is my beginning of contribution.
@cgoldberg we should treat unsuccessful http status code as error and raise exception in any case. Specification explicitly says about it: https://www.w3.org/TR/webdriver2/#errors