@@ -423,7 +423,7 @@ public ITargetLocator SwitchTo()
423
423
/// <returns>The value returned by the script.</returns>
424
424
public object ExecuteScript ( string script , params object [ ] args )
425
425
{
426
- return this . ExecuteScriptInternal ( script , false , args ) ;
426
+ return this . ExecuteScriptCommand ( script , DriverCommand . ExecuteScript , args ) ;
427
427
}
428
428
429
429
/// <summary>
@@ -434,7 +434,7 @@ public object ExecuteScript(string script, params object[] args)
434
434
/// <returns>The value returned by the script.</returns>
435
435
public object ExecuteAsyncScript ( string script , params object [ ] args )
436
436
{
437
- return this . ExecuteScriptInternal ( script , true , args ) ;
437
+ return this . ExecuteScriptCommand ( script , DriverCommand . ExecuteAsyncScript , args ) ;
438
438
}
439
439
#endregion
440
440
@@ -903,6 +903,33 @@ protected virtual RemoteWebElement CreateElement(string elementId)
903
903
RemoteWebElement toReturn = new RemoteWebElement ( this , elementId ) ;
904
904
return toReturn ;
905
905
}
906
+
907
+ protected object ExecuteScriptCommand ( string script , string commandName , params object [ ] args )
908
+ {
909
+ if ( ! this . Capabilities . IsJavaScriptEnabled )
910
+ {
911
+ throw new NotSupportedException ( "You must be using an underlying instance of WebDriver that supports executing javascript" ) ;
912
+ }
913
+
914
+ // Escape the quote marks
915
+ // script = script.Replace("\"", "\\\"");
916
+ object [ ] convertedArgs = ConvertArgumentsToJavaScriptObjects ( args ) ;
917
+
918
+ Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
919
+ parameters . Add ( "script" , script ) ;
920
+
921
+ if ( convertedArgs != null && convertedArgs . Length > 0 )
922
+ {
923
+ parameters . Add ( "args" , convertedArgs ) ;
924
+ }
925
+ else
926
+ {
927
+ parameters . Add ( "args" , new object [ ] { } ) ;
928
+ }
929
+
930
+ Response commandResponse = this . Execute ( commandName , parameters ) ;
931
+ return this . ParseJavaScriptReturnValue ( commandResponse . Value ) ;
932
+ }
906
933
#endregion
907
934
908
935
#region Private methods
@@ -962,6 +989,11 @@ private static object ConvertObjectToJavaScriptObject(object arg)
962
989
return converted ;
963
990
}
964
991
992
+ /// <summary>
993
+ /// Converts the arguments to java script objects.
994
+ /// </summary>
995
+ /// <param name="args">The arguments.</param>
996
+ /// <returns></returns>
965
997
private static object [ ] ConvertArgumentsToJavaScriptObjects ( object [ ] args )
966
998
{
967
999
if ( args == null )
@@ -1060,34 +1092,6 @@ private static void UnpackAndThrowOnError(Response errorResponse)
1060
1092
}
1061
1093
}
1062
1094
1063
- private object ExecuteScriptInternal ( string script , bool async , params object [ ] args )
1064
- {
1065
- if ( ! this . Capabilities . IsJavaScriptEnabled )
1066
- {
1067
- throw new NotSupportedException ( "You must be using an underlying instance of WebDriver that supports executing javascript" ) ;
1068
- }
1069
-
1070
- // Escape the quote marks
1071
- // script = script.Replace("\"", "\\\"");
1072
- object [ ] convertedArgs = ConvertArgumentsToJavaScriptObjects ( args ) ;
1073
-
1074
- Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
1075
- parameters . Add ( "script" , script ) ;
1076
-
1077
- if ( convertedArgs != null && convertedArgs . Length > 0 )
1078
- {
1079
- parameters . Add ( "args" , convertedArgs ) ;
1080
- }
1081
- else
1082
- {
1083
- parameters . Add ( "args" , new object [ ] { } ) ;
1084
- }
1085
-
1086
- string command = async ? DriverCommand . ExecuteAsyncScript : DriverCommand . ExecuteScript ;
1087
- Response commandResponse = this . Execute ( command , parameters ) ;
1088
- return this . ParseJavaScriptReturnValue ( commandResponse . Value ) ;
1089
- }
1090
-
1091
1095
private object ParseJavaScriptReturnValue ( object responseValue )
1092
1096
{
1093
1097
object returnValue = null ;
0 commit comments