Skip to content

Commit 1560ca4

Browse files
committed
Extracting JSON wire protocol element marker property names in .NET
1 parent 1ef54a6 commit 1560ca4

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,13 @@ internal IWebElement GetElementFromResponse(Response response)
10181018
// TODO: Remove this "if" logic once the spec is properly updated
10191019
// and remote-end implementations comply.
10201020
string id = string.Empty;
1021-
if (elementDictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf"))
1021+
if (elementDictionary.ContainsKey(RemoteWebElement.ElementReferencePropertyName))
10221022
{
1023-
id = (string)elementDictionary["element-6066-11e4-a52e-4f735466cecf"];
1023+
id = (string)elementDictionary[RemoteWebElement.ElementReferencePropertyName];
10241024
}
1025-
else if (elementDictionary.ContainsKey("ELEMENT"))
1025+
else if (elementDictionary.ContainsKey(RemoteWebElement.LegacyElementReferencePropertyName))
10261026
{
1027-
id = (string)elementDictionary["ELEMENT"];
1027+
id = (string)elementDictionary[RemoteWebElement.LegacyElementReferencePropertyName];
10281028
}
10291029

10301030
element = this.CreateElement(id);
@@ -1052,13 +1052,13 @@ internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response respon
10521052
// TODO: Remove this "if" logic once the spec is properly updated
10531053
// and remote-end implementations comply.
10541054
string id = string.Empty;
1055-
if (elementDictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf"))
1055+
if (elementDictionary.ContainsKey(RemoteWebElement.ElementReferencePropertyName))
10561056
{
1057-
id = (string)elementDictionary["element-6066-11e4-a52e-4f735466cecf"];
1057+
id = (string)elementDictionary[RemoteWebElement.ElementReferencePropertyName];
10581058
}
1059-
else if (elementDictionary.ContainsKey("ELEMENT"))
1059+
else if (elementDictionary.ContainsKey(RemoteWebElement.LegacyElementReferencePropertyName))
10601060
{
1061-
id = (string)elementDictionary["ELEMENT"];
1061+
id = (string)elementDictionary[RemoteWebElement.LegacyElementReferencePropertyName];
10621062
}
10631063

10641064
RemoteWebElement element = this.CreateElement(id);
@@ -1297,7 +1297,7 @@ private static object ConvertObjectToJavaScriptObject(object arg)
12971297
{
12981298
// TODO: Remove "ELEMENT" addition when all remote ends are spec-compliant.
12991299
Dictionary<string, object> elementDictionary = argAsElementReference.ToDictionary();
1300-
elementDictionary.Add("ELEMENT", argAsElementReference.ElementReferenceId);
1300+
elementDictionary.Add(RemoteWebElement.LegacyElementReferencePropertyName, argAsElementReference.ElementReferenceId);
13011301
converted = elementDictionary;
13021302
}
13031303
else if (argAsDictionary != null)
@@ -1474,15 +1474,15 @@ private object ParseJavaScriptReturnValue(object responseValue)
14741474

14751475
if (resultAsDictionary != null)
14761476
{
1477-
if (resultAsDictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf"))
1477+
if (resultAsDictionary.ContainsKey(RemoteWebElement.ElementReferencePropertyName))
14781478
{
1479-
string id = (string)resultAsDictionary["element-6066-11e4-a52e-4f735466cecf"];
1479+
string id = (string)resultAsDictionary[RemoteWebElement.ElementReferencePropertyName];
14801480
RemoteWebElement element = this.CreateElement(id);
14811481
returnValue = element;
14821482
}
1483-
else if (resultAsDictionary.ContainsKey("ELEMENT"))
1483+
else if (resultAsDictionary.ContainsKey(RemoteWebElement.LegacyElementReferencePropertyName))
14841484
{
1485-
string id = (string)resultAsDictionary["ELEMENT"];
1485+
string id = (string)resultAsDictionary[RemoteWebElement.LegacyElementReferencePropertyName];
14861486
RemoteWebElement element = this.CreateElement(id);
14871487
returnValue = element;
14881488
}

dotnet/src/webdriver/Remote/RemoteWebElement.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ namespace OpenQA.Selenium.Remote
3535
/// <seealso cref="ILocatable"/>
3636
public class RemoteWebElement : IWebElement, IFindsByLinkText, IFindsById, IFindsByName, IFindsByTagName, IFindsByClassName, IFindsByXPath, IFindsByPartialLinkText, IFindsByCssSelector, IWrapsDriver, ILocatable, ITakesScreenshot, IWebElementReference
3737
{
38+
/// <summary>
39+
/// The property name that represents a web element in the wire protocol.
40+
/// </summary>
41+
public const string ElementReferencePropertyName = "element-6066-11e4-a52e-4f735466cecf";
42+
43+
/// <summary>
44+
/// The property name that represents a web element in the legacy dialect of the wire protocol.
45+
/// </summary>
46+
public const string LegacyElementReferencePropertyName = "ELEMENT";
47+
3848
private RemoteWebDriver driver;
3949
private string elementId;
4050

@@ -943,7 +953,7 @@ public override bool Equals(object obj)
943953
Dictionary<string, object> IWebElementReference.ToDictionary()
944954
{
945955
Dictionary<string, object> elementDictionary = new Dictionary<string, object>();
946-
elementDictionary.Add("element-6066-11e4-a52e-4f735466cecf", this.elementId);
956+
elementDictionary.Add(ElementReferencePropertyName, this.elementId);
947957
return elementDictionary;
948958
}
949959

0 commit comments

Comments
 (0)