Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Annotate nullability on more of WebElement #15230

Open
wants to merge 11 commits into
base: trunk
Choose a base branch
from
11 changes: 6 additions & 5 deletions dotnet/src/webdriver/WebElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,6 @@ public virtual ISearchContext GetShadowRoot()
return shadowRoot;
}

#nullable restore

/// <summary>
/// Gets the value of a CSS property of this element.
/// </summary>
Expand All @@ -549,10 +547,13 @@ public virtual string GetCssValue(string propertyName)

Response commandResponse = this.Execute(DriverCommand.GetElementValueOfCssProperty, parameters);

return commandResponse.Value.ToString();
}
if (commandResponse.Value is null)
{
throw new WebDriverException("GetElementValueOfCssProperty command returned a successful result, but contained no data");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test it carefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to be very careful with this, to change no behavior. I read the spec, it says this will always be a string.

The only reason I am comfortable with this change, is because it would previously be a NullReferenceException if this were null. This way, users have something better to report if there is a bug here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very good insight. Please give me a chance to revisit it.

}

#nullable enable
return commandResponse.Value.ToString()!;
}

/// <summary>
/// Gets a <see cref="Screenshot"/> object representing the image of this element on the screen.
Expand Down
Loading