Skip to content

Commit 79e3f9e

Browse files
nvborisenkodiemol
andauthored
[dotnet] Fallback result parsing of script execution to expected type (#11930)
Fallback result parsing of script execution Co-authored-by: Diego Molina <[email protected]>
1 parent 542f0a1 commit 79e3f9e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

dotnet/src/support/Extensions/WebDriverExtensions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,20 @@ public static T ExecuteJavaScript<T>(this IWebDriver driver, string script, para
101101
throw new WebDriverException("Script returned null, but desired type is a value type");
102102
}
103103
}
104-
else if (!type.IsInstanceOfType(value))
104+
else if (type.IsInstanceOfType(value))
105105
{
106-
throw new WebDriverException("Script returned a value, but the result could not be cast to the desired type");
106+
result = (T)value;
107107
}
108108
else
109109
{
110-
result = (T)value;
110+
try
111+
{
112+
result = (T)Convert.ChangeType(value, type);
113+
}
114+
catch(Exception exp)
115+
{
116+
throw new WebDriverException("Script returned a value, but the result could not be cast to the desired type", exp);
117+
}
111118
}
112119

113120
return result;

0 commit comments

Comments
 (0)