question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
mxschmittcommented, Aug 2, 2020

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.

5reactions
rinogocommented, Mar 12, 2021

For those needing an example of how to do this, check this updated sandbox:

https://try.playwright.tech/?s=t5tfy46

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Element.value vs Element.getAttribute("value")
I've started learning JavaScript recently but there's something that I'm confused with : what is the different between Element.value and Element ...
Read more >
Element.getAttribute() - Web APIs | MDN
The getAttribute() method of the Element interface returns the value of a specified attribute on the element.
Read more >
getAttribute() in Selenium Web Driver: Get Started In 5 Steps
Yet another Selenium method can confuse people: getCssValue(). So, what's this method, and how it differs from getAttribute()?.
Read more >
Xrm.Page.getAttribute looking for value on the page but not ...
I'm using Xrm.Page.getAttribute("").getvalue() to check if a field is null or not before progressing forward. If it's null throw a popup to fill...
Read more >
How to get attribute values for products in Magento 1.9
Shall i use the same coding in my page? i just edit the "color" into my product id. – Saranya. Nov 15, 2016...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found