Skip to content

Commit a573338

Browse files
committed
Updating IWebElement.GetAttribute shim for W3C protocol compliant drivers
1 parent 1b4a0f8 commit a573338

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

dotnet/src/webdriver/Remote/RemoteWebElement.cs

+30-2
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,39 @@ public void Click()
400400
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
401401
public string GetAttribute(string attributeName)
402402
{
403+
Response commandResponse = null;
404+
string attributeValue = string.Empty;
403405
Dictionary<string, object> parameters = new Dictionary<string, object>();
404406
parameters.Add("id", this.elementId);
405407
parameters.Add("name", attributeName);
406-
Response commandResponse = this.Execute(DriverCommand.GetElementAttribute, parameters);
407-
string attributeValue = string.Empty;
408+
if (this.driver.IsSpecificationCompliant)
409+
{
410+
List<string> booleanAttributes = new List<string>()
411+
{
412+
"default", "typemustmatch", "checked", "defer", "async", "muted",
413+
"reversed", "required", "controls", "ismap", "disabled", "novalidate",
414+
"readonly", "allowfullscreen", "selected", "formnovalidate",
415+
"multiple", "autofocus", "open", "loop", "autoplay"
416+
};
417+
418+
if (attributeName == "style")
419+
{
420+
return this.driver.ExecuteScript("return arguments[0].style.cssText", this).ToString();
421+
}
422+
423+
commandResponse = this.Execute(DriverCommand.GetElementProperty, parameters);
424+
if ((commandResponse.Value == null ||
425+
((commandResponse.Value.ToString() == string.Empty || commandResponse.Value.ToString() == bool.FalseString) && attributeName != "value")) ||
426+
booleanAttributes.Contains(attributeName))
427+
{
428+
commandResponse = this.Execute(DriverCommand.GetElementAttribute, parameters);
429+
}
430+
}
431+
else
432+
{
433+
commandResponse = this.Execute(DriverCommand.GetElementAttribute, parameters);
434+
}
435+
408436
if (commandResponse.Value == null)
409437
{
410438
attributeValue = null;

0 commit comments

Comments
 (0)