Skip to content

Commit 688172f

Browse files
unknownunknown
authored andcommitted
Added the ability to send customized requests (driver.Send)
1 parent 96d1e09 commit 688172f

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

Selenium/ComInterfaces/_WebDriver.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public interface _WebDriver {
4646
[DispId(20), Description("Quits this driver, closing every associated window. Same as stop.")]
4747
void Quit();
4848

49+
[DispId(31), Description("Sends a customized command.")]
50+
object Send(string method, string relativeUri,
51+
string param1 = null, string value1 = null,
52+
string param2 = null, string value2 = null,
53+
string param3 = null, string value3 = null,
54+
string param4 = null, string value4 = null);
55+
4956
#endregion
5057

5158

Selenium/WebDriver.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public void Start(string browser = null, string baseUrl = null) {
269269
/// <param name="version">Browser version</param>
270270
/// <param name="platform">Platform: WINDOWS, LINUX, MAC, ANDROID...</param>
271271
/// <example>
272-
/// <code lang="vbs">
272+
/// <code lang="vbs">
273273
/// Dim driver As New WebDriver()
274274
/// driver.StartRemotely "http://localhost:4444/wd/hub", "ie", 11
275275
/// driver.Get "/"
@@ -369,6 +369,59 @@ private string ExpendBrowserName(string browser) {
369369
}
370370
}
371371

372+
/// <summary>
373+
/// Sends a customized command
374+
/// </summary>
375+
/// <param name="method">POST, GET or DELETE</param>
376+
/// <param name="relativeUri">Relative URI. Ex: "/screenshot"</param>
377+
/// <param name="param1">Optional</param>
378+
/// <param name="value1"></param>
379+
/// <param name="param2">Optional</param>
380+
/// <param name="value2"></param>
381+
/// <param name="param3">Optional</param>
382+
/// <param name="value3"></param>
383+
/// <param name="param4">Optional</param>
384+
/// <param name="value4"></param>
385+
/// <returns>Result</returns>
386+
/// <example>
387+
/// <code lang="vbs">
388+
/// Set links = driver.Send("POST", "/elements", "using", "css selector", "value", "a")
389+
/// </code>
390+
/// </example>
391+
public object Send(string method, string relativeUri,
392+
string param1 = null, string value1 = null,
393+
string param2 = null, string value2 = null,
394+
string param3 = null, string value3 = null,
395+
string param4 = null, string value4 = null) {
396+
397+
RequestMethod mth = 0;
398+
switch (method.ToUpper()) {
399+
case "POST": mth = RequestMethod.POST; break;
400+
case "GET": mth = RequestMethod.GET; break;
401+
case "DELETE": mth = RequestMethod.DELETE; break;
402+
default:
403+
throw new Errors.ArgumentError("Unhandled method: " + method);
404+
}
405+
406+
Dictionary data = null;
407+
if (param1 != null) {
408+
data = new Dictionary();
409+
data.Add(param1, value1);
410+
if (param2 != null) {
411+
data.Add(param2, value2);
412+
if (param3 != null) {
413+
data.Add(param3, value3);
414+
if (param4 != null) {
415+
data.Add(param4, value3);
416+
}
417+
}
418+
}
419+
}
420+
object result = session.Send(mth, relativeUri, data);
421+
return result;
422+
}
423+
424+
372425
#endregion
373426

374427

0 commit comments

Comments
 (0)