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]: element.get_dom_attribute("checked") for a checked checkbox element is not returning True #14800

Closed
mdmintz opened this issue Nov 25, 2024 · 11 comments

Comments

@mdmintz
Copy link
Contributor

mdmintz commented Nov 25, 2024

What happened?

element.get_dom_attribute("checked") for a checked checkbox element is not returning True

In 4.27.0, element.get_attribute() was deprecated in favor of element.get_dom_attribute(). However, the new method does not get the correct results, as in the following example where I was determining whether or not a checkbox was checked:

(Pdb+) element.tag_name
'input'
(Pdb+) attribute
'checked'
(Pdb+) element.get_attribute(attribute)
'true'
(Pdb+) element.get_dom_attribute(attribute)
(Pdb+) element.get_dom_attribute(attribute)
(Pdb+)

How can we reproduce the issue?

Call `element.get_dom_attribute(attribute)` for an `input` element of `type="checkbox"`, where the checkbox is checked.

There's no output.

The deprecated method, `element.get_attribute(attribute)`, correctly returns `true`.

Relevant log output

(Pdb+) element.tag_name
'input'
(Pdb+) attribute
'checked'
(Pdb+) element.get_attribute(attribute)
'true'
(Pdb+) element.get_dom_attribute(attribute)
(Pdb+) element.get_dom_attribute(attribute)
(Pdb+)

Operating System

Any

Selenium version

Python - 4.27.0

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

Chrome

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

Latest

Are you using Selenium Grid?

No

Copy link

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

@mdmintz
Copy link
Contributor Author

mdmintz commented Nov 25, 2024

Screenshot 2024-11-25 at 1 58 26 PM

@AutomatedTester
Copy link
Member

AutomatedTester commented Nov 25, 2024 via email

@joerg1985
Copy link
Member

To read the checked state getDomProperty should be used. Some words on why i think this depreation is something good:

  • the implementation did not return false in case the element was not checkable at all, so you might check the wrong element and do not realize it
  • on page javascript could lead to incorrect results, in case someone did set a property named like the attribute
  • the behavoiur was inconsistent, e.g. reading the src of an img returned null if not defined, lowsrc did return an empty string
  • the implementation did things not documented, e.g. for the spellcheck attribute and ignored the element does support spellcheck at all
  • the javascript is multiple kb big, so people complained about the slowness

and these are only the points i can recall, without even beeing in the discussion at the tlc meeting.

@AutomatedTester
Copy link
Member

What @jimevans said is oversimplified (his words). Most of the times attributes and properties are mirrored so won't matter.

@mdmintz
Copy link
Contributor Author

mdmintz commented Nov 25, 2024

It's still being used in Selenium 4.27.0:

if opt.get_attribute("index") == match:

if opt.get_attribute("index") == str(index):

Select(element).select_by_index(option)

...python3.13/site-packages/selenium/webdriver/support/select.py:97: DeprecationWarning: using WebElement.get_attribute() has been deprecated. Please use get_dom_attribute() instead. if opt.get_attribute("index") == match:


So either the deprecation must be removed, or all instances of get_attribute() in Selenium must be replaced.

@mdmintz
Copy link
Contributor Author

mdmintz commented Nov 26, 2024

Lots of places where get_attribute() can still be found being used in selenium 4.27.0:
https://github.com/search?q=repo%3ASeleniumHQ%2Fselenium%20get_attribute&type=code

Perhaps removing the deprecation is the best option for the time being.

@Delta456
Copy link
Contributor

We can also update the instances of get_attribute() in Selenium as the release is already done.

@diemol
Copy link
Member

diemol commented Nov 26, 2024

We are going to revert this. Thanks, @VietND96, for creating the PR.

For 4.28, we will put back the deprecation code AND replace all the usages of get_attribute() to avoid the warnings.

@diemol
Copy link
Member

diemol commented Nov 26, 2024

https://pypi.org/project/selenium/4.27.1/

@diemol diemol closed this as completed Nov 26, 2024
@diemol
Copy link
Member

diemol commented Nov 26, 2024

Thank you, @VietND96!

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

5 participants