Skip to content

Commit 563ea46

Browse files
committed
added new methods after getattribute
1 parent e189ca8 commit 563ea46

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

examples/javascript/test/elements/information.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ describe('Element Information Test', function () {
5757

5858
//fetch the attribute "name" associated with the textbox
5959
const nameAttribute = await emailElement.getAttribute("name");
60+
61+
// New in Selenium 4.27+
62+
// fetches the DOM attribute exactly as written in the HTML source
63+
const domAttribute = await emailElement.getDomAttribute("name");
64+
console.log("DOM Attribute:", domAttribute);
65+
66+
// fetches the live property value from the DOM object (may differ at runtime)
67+
const domProperty = await emailElement.getDomProperty("name");
68+
console.log("DOM Property:", domProperty);
6069

6170
assert.equal(nameAttribute, "email_input")
6271
});

website_and_docs/content/documentation/webdriver/elements/information.en.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ val text = driver.findElement(By.id("justanotherlink")).getText()
253253

254254
## Fetching Attributes or Properties
255255

256-
Fetches the run time value associated with a
257-
DOM attribute. It returns the data associated
258-
with the DOM attribute or property of the element.
256+
To interact with element attributes and properties, Selenium provides specific methods for predictable results. It is important to understand the difference:
257+
* Attribute: The initial value defined in the HTML source code.
258+
* Property: The current value in the browser's DOM, which can be modified by JavaScript or user interaction. For instance, if a user types in an input field, the value property changes.
259+
260+
For this reason, Selenium has two precise methods to get these values: getDomAttribute() and getDomProperty(). The older getAttribute() method is still available for backward compatibility, but its use is discouraged as it can lead to unpredictable results and slower execution.
259261

260262
{{< tabpane langEqualsHeader=true >}}
261263
{{< tab header="Java" text=true >}}
@@ -271,7 +273,7 @@ with the DOM attribute or property of the element.
271273
{{< gh-codeblock path="/examples/ruby/spec/elements/information_spec.rb#L48">}}
272274
{{< /tab >}}
273275
{{< tab header="JavaScript" text=true >}}
274-
{{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L55-L59">}}
276+
{{< gh-codeblock path="/examples/javascript/test/elements/information.spec.js#L55-L68">}}
275277
{{< /tab >}}
276278
{{< tab header="Kotlin" >}}
277279
// Navigate to URL

0 commit comments

Comments
 (0)