Skip to content

Commit

Permalink
[dotnet] Fallback result parsing of script execution to expected type (
Browse files Browse the repository at this point in the history
…#11930)

Fallback result parsing of script execution

Co-authored-by: Diego Molina <[email protected]>
  • Loading branch information
nvborisenko and diemol authored Apr 24, 2023
1 parent 542f0a1 commit 79e3f9e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions dotnet/src/support/Extensions/WebDriverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,20 @@ public static T ExecuteJavaScript<T>(this IWebDriver driver, string script, para
throw new WebDriverException("Script returned null, but desired type is a value type");
}
}
else if (!type.IsInstanceOfType(value))
else if (type.IsInstanceOfType(value))
{
throw new WebDriverException("Script returned a value, but the result could not be cast to the desired type");
result = (T)value;
}
else
{
result = (T)value;
try
{
result = (T)Convert.ChangeType(value, type);
}
catch(Exception exp)
{
throw new WebDriverException("Script returned a value, but the result could not be cast to the desired type", exp);
}
}

return result;
Expand Down

0 comments on commit 79e3f9e

Please sign in to comment.