Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit aaba73b

Browse files
committed
added the new version of Get Element Attribute which uses 2 parameters instead of just 1.
1 parent cc61a10 commit aaba73b

File tree

1 file changed

+19
-5
lines changed
  • src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords

1 file changed

+19
-5
lines changed

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,32 @@ public void elementTextShouldNotBe(String locator, String text, String...params)
429429
"\r\n" +
430430
"The ``attribute_locator`` consists of element locator followed by an @ sign and attribute name. Example: element_id@class\r\n" +
431431
"\r\n" +
432-
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.")
432+
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.\r\n" +
433+
"\r\n" +
434+
"Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.")
433435
@ArgumentNames({ "attributeLocator" })
436+
@Deprecated
434437
public String getElementAttribute(String attributeLocator) {
435438
String[] parts = parseAttributeLocator(attributeLocator);
439+
return getElementAttribute(parts[0], parts[1]);
440+
}
436441

437-
List<WebElement> elements = elementFind(parts[0], true, false);
442+
@RobotKeyword("Returns value of attribute from element locator.\r\n" +
443+
"\r\n" +
444+
"See the `Locating elements` section for details about the locator syntax.\r\n" +
445+
"\r\n" +
446+
"Example: ${id}= Get Element Attribute css:h1 id\r\n" +
447+
"\r\n" +
448+
"Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.")
449+
@ArgumentNames({ "locator", "attribute" })
450+
public String getElementAttribute(String locator, String attribute) {
451+
452+
List<WebElement> elements = elementFind(locator, true, false);
438453

439454
if (elements.size() == 0) {
440-
throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", parts[0]));
455+
throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", locator));
441456
}
442-
443-
return elements.get(0).getAttribute(parts[1]);
457+
return elements.get(0).getAttribute(attribute);
444458
}
445459

446460
@RobotKeyword("Clears the text from element identified by ``locator``.\r\n" +

0 commit comments

Comments
 (0)