Skip to content

[Feature] page.getAttribute('value') confuses people #3265

@mxschmitt

Description

@mxschmitt

Situation:
For users who are migrating from Selenium over to Playwright it might be confusing that we handle the element attributes in the getAttribute() method strictly and returning by that only element attributes. For them it might be logical that it returns properties too. I agree on that.

Selenium:
Selenium solves this by trying to get the property first and using the attributes as a fallback, see here:

https://github.com/SeleniumHQ/selenium/blob/941dc9c6b2e2aa4f701c1b72be8de03d4b7e996a/java/client/src/org/openqa/selenium/WebElement.java#L96-L130

Possible solutions:
Since Pavel proposed to not modify the getAttribute() method since it would then work differently what the name says, I would maybe add a helper function to it. Usage could look like as follows:

page.getElementValue("#foo", "value") // not sure about a better function name

Example
See the following example which works on Selenium but not on Playwright once you migrate over to Playwright: https://try.playwright.tech/?s=27y84

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions