Skip to content

[🐛 Bug]: ExecuteJavaScript<double> fails if the number has no decimal part #11801

@VulumeCode

Description

@VulumeCode

What happened?

In Chrome Browser.ExecuteJavaScript<double>("{return performance.timeOrigin ;}"); fails 1 in 10 times because it returns a double truncated to 1 decimal. However when the decimal part is 0 Selenium sees this as a long, which is not IsInstanceOfType double, so it crashes with WebDriverException("Script returned a value, but the result could not be cast to the desired type");.

This means that it is in general not possible to use double for ExecuteJavaScript, even though it often seems correct.

How can we reproduce the issue?

`Browser.ExecuteJavaScript<double>("{return 123.0;}");`

Relevant log output

OpenQA.Selenium.WebDriverException : Script returned a value, but the result could not be cast to the desired type at OpenQA.Selenium.Support.Extensions.WebDriverExtensions.ExecuteJavaScript[T](IWebDriver driver, String script, Object[] args)

Operating System

Windows 10

Selenium version

.Net 4.8.1

What are the browser(s) and version(s) where you see this issue?

Chrome 111

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 111

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-dotnet.NET BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions