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:
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
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 missingvalueattribute on an input/textarea. We could also introduceinputValue()next totectContentfor 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
Most helpful comment
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.