Playwright: [Feature] page.inputValue() that reads from the value property, not the attribute

Created on 1 Aug 2020  路  5Comments  路  Source: microsoft/playwright

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

P3-collecting-feedback

Most helpful comment

I'd say your expectations are broken, but it does not mean this is not a migration problem. We could warn the user that they want evaluate(e => e.value) when they get missing value attribute on an input/textarea. We could also introduce inputValue() next to tectContent for convenience.

Let's see how many users will face into that issue and then add the suggested feature like a warning and a inputValue() function e.g.

All 5 comments

I'd say your expectations are broken, but it does not mean this is not a migration problem. We could warn the user that they want evaluate(e => e.value) when they get missing value attribute on an input/textarea. We could also introduce inputValue() next to tectContent for convenience.

I'd say your expectations are broken, but it does not mean this is not a migration problem. We could warn the user that they want evaluate(e => e.value) when they get missing value attribute on an input/textarea. We could also introduce inputValue() next to tectContent for convenience.

Let's see how many users will face into that issue and then add the suggested feature like a warning and a inputValue() function e.g.

Faced the same issue, solved by await page.$eval('input[type=\"email\"]', el => el.value) but as i understand it doesn't wait for element am I wrong?

@niyarlatotep you are right, $eval etc. does not wait for the actionability checks.

@mxschmitt so it's not equivalent to textConten, it would be better to have a method with the same behaviour imho, but it's not so critical though

Was this page helpful?
0 / 5 - 0 ratings