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

[🐛 Bug]: IWebElement.GetDomProperty("style") returns "System.Collections.Generic.Dictionary`2[System.String,System.Object]" (as string) #14846

Open
Mek7 opened this issue Dec 3, 2024 · 3 comments

Comments

@Mek7
Copy link

Mek7 commented Dec 3, 2024

What happened?

I am upgrading Selenium test code in .NET 8 from Selenium.Support version 4.25.0 to 4.27.0
Because IWebElement.GetAttribute() method is now marked as deprecated, I replaced it with GetDomProperty().
For example:
webDriver.FindElement(By....whatever).GetDomProperty("style")
should return a string like
background: rgb(65, 131, 215); height: 8.125%;
but returns this string:
System.Collections.Generic.Dictionary2[System.String,System.Object]`
Looks like a bug - that string is the string representation of calling .ToString() on a Dictionary instance.
Or is it supposed to work like this?

When I use GetDomAttribute() instead of GetDomProperty(), the correct string is returned:
background: rgb(65, 131, 215); height: 8.125%;

How can we reproduce the issue?

See above in "What happened"

Relevant log output

Not sure - using Selenium in Visual Studio unit test framework. Not seeing any useful stuff in debug output.

Operating System

Windows 11

Selenium version

.NET 4.27.0

What are the browser(s) and version(s) where you see this issue?

Firefox 132.0.2

What are the browser driver(s) and version(s) where you see this issue?

GeckoDriver 0.35.0

Are you using Selenium Grid?

no

Copy link

github-actions bot commented Dec 3, 2024

@Mek7, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@nvborisenko
Copy link
Member

For maintainers:

GetDomProperty:

var style = element.GetDomProperty("style");
Console.WriteLine(style); // System.Object[]
21:00:42.948 TRACE HttpCommandExecutor: >> GET RequestUri: http://localhost:57238/session/92b41016a843a63333ee03f6aa03c648/element/f.533155AB6C15ADAF23E24748C23919EA.d.A26436E61238A5F5AA2A84DDBC427528.e.12/property/style, Content: null, Headers: 3
21:00:42.955 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: OK, Content: System.Net.Http.HttpConnectionResponseContent, Headers: 1
{"value":["height","line-height","width"]}

GetDomAttribute:

var style = element.GetDomAttribute("style");
Console.WriteLine(style); // height:20px;line-height:20px;width:20px
21:11:53.355 TRACE HttpCommandExecutor: >> GET RequestUri: http://localhost:56622/session/e66e568e99e1ec12698fef989bd7173e/element/f.36FADB5E54CA2D7404527200702A6B67.d.BBE3AC63C943932979074E4D6C823EDA.e.13/attribute/style, Content: null, Headers: 3
21:11:53.362 TRACE HttpCommandExecutor: << StatusCode: 200, ReasonPhrase: OK, Content: System.Net.Http.HttpConnectionResponseContent, Headers: 1
{"value":"height:20px;line-height:20px;width:20px"}

I thought I broke it recently, but no, the same behavior using "old" selenium versions.

For @Mek7, seems in your case it is better to use DomAttribute?

In any case string representation of GetDomProperty() should be better! Given that it returns string, it must be even better!

@Mek7
Copy link
Author

Mek7 commented Dec 3, 2024

Yes, GetDomAttribute() works OK but GetDomProperty() returns the ToString() result of a dictionary.
Both methods return string. When I migrated the old code, when one did not work, I used the other :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants