selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🚀 Feature]: deprecate WebElement.getAttribute

Open joerg1985 opened this issue 1 year ago • 7 comments

Feature and motivation

WebElement.getDomAttribute and WebElement.getDomProperty have been added in Selenium 4.

It might be good to deprecate WebElement.getAttribute to remove it at a undefined time in the future.

Usage example

This would warn people to move to the 'new' methods when maintaining existing code.

joerg1985 avatar Dec 19 '23 15:12 joerg1985

@joerg1985, 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!

github-actions[bot] avatar Dec 19 '23 15:12 github-actions[bot]

Bold.

I'm not completely against the idea, but also not sure it's the right call.

titusfortner avatar Dec 20 '23 13:12 titusfortner

Feature and motivation

WebElement.getDomAttribute and WebElement.getDomProperty have been added in Selenium 4.

It might be good to deprecate WebElement.getAttribute to remove it at a undefined time in the future.

Usage example

This would warn people to move to the 'new' methods when maintaining existing code.

Let me ask, are the 3 APIs above different?

NCLnclNCL avatar Dec 20 '23 14:12 NCLnclNCL

getAttribute() assumes that people don't know the difference between a property and an attribute and don't want to be bothered to figure it out (a decent assumption), so it uses a bunch of fancy JavaScript that does a pretty good job of guessing whether the user is looking for the property or the attribute and returning that value. It's great convenience, but it is now implemented with a client side atom which means a large payload gets sent to the driver/server on every usage.

The ideal world people figure out if they want an attribute or property and use the correct method. But that might be asking a lot of users, and we already have the code right there...

titusfortner avatar Dec 20 '23 15:12 titusfortner

I was reading the blog post and the javadoc before opening the issue, this gave me the feeling the getAttribute method is the legacy way of reading attributes/properties.

If this is not true and there are no plans to ever remove the getAttribute method, this issue can be closed.

If this is a legacy method, it might be good to mark it deprecated or make a clear statement in the docs to ensure no new code is using this. I agree there is alot of code using this, therefore a deprecation notice could be added, something like: don't panic, this method will not be removed before selenium 6, but should not be used in new code.

joerg1985 avatar Dec 20 '23 19:12 joerg1985

It would definitely be valuable to encourage people to use the other methods.

titusfortner avatar Dec 20 '23 19:12 titusfortner

We decided in TLC Meeting 1/18 that we would go ahead and mark this feature deprecated to encourage people to move to the more precise property and attribute methods.

We need a blog post explaining everything though, and I'm still not sure we want to actually remove it any time soon because it is quite useful.

titusfortner avatar Jan 20 '24 18:01 titusfortner