SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.57k stars 8.17k forks source link

[🐛 Bug]: getDomAttribute and getAttribute do the same thing (?) #10244

Closed aphx07 closed 2 years ago

aphx07 commented 2 years ago

What happened?

Not sure if this is a bug but I can't tell without documentation on these methods. In Java there are two methods that seem to return the same information: getDomAttribute and getAttribute. I have tested them against few examples. Are they duplicates or am I missing something?

How can we reproduce the issue?

@Test
    public void exampleTest1(){
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        driver.get("https://fakestore.testelka.pl/product/windsurfing-w-lanzarote-costa-teguise/");
        WebElement element = driver.findElement(By.cssSelector("[name='quantity']"));
        String attribute = element.getDomAttribute("id");
        String attribute2 = element.getAttribute("id");
        System.out.println("Attribute 1: " + attribute + "\nAttribute 2: " + attribute2);
    }

Relevant log output

Attribute 1: quantity_61dd90fb756b4
Attribute 2: quantity_61dd90fb756b4

Operating System

Windows 11 Pro

Selenium version

Java 4.1.1

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

Chrome 97.0.4692.71

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

ChromeDriver 97.0.4692.71

Are you using Selenium Grid?

No response

github-actions[bot] commented 2 years ago

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

titusfortner commented 2 years ago

I've got a partial blog post written about this that I haven't published.

Most people don't know the difference between an element attribute and an element property, so the traditional getAttribute method returns either the attribute or the property depending on which the you probably want. It does a good job of this. When moving to a w3c standard, though, we can't define a "best guess at what user wants" endpoint, so there is an attribute endpoint and a property endpoint. For backwards compatibility, we kept the original behavior for getAttribute and it is now implemented by sending a large chunk of JavaScript to the browser. The new methods are named slightly differently in different languages, but essentially getDomAttribute & getDomProperty which always return the exact value for property and attribute.

aphx07 commented 2 years ago

Thanks for the clarification!

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.