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

Added the missing @RobotKeywordOverload. This annotation is needed to… #84

Merged
merged 3 commits into from
Aug 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.robotframework.javalib.annotation.ArgumentNames;
import org.robotframework.javalib.annotation.Autowired;
import org.robotframework.javalib.annotation.RobotKeyword;
import org.robotframework.javalib.annotation.RobotKeywords;
import org.robotframework.javalib.annotation.*;

import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter;
import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException;
Expand Down Expand Up @@ -423,17 +420,9 @@ public void elementTextShouldNotBe(String locator, String text, String...params)
}
}

@RobotKeyword("Returns the value of an element attribute.\r\n" +
"\r\n" +
"The ``attribute_locator`` consists of element locator followed by an @ sign and attribute name. Example: element_id@class\r\n" +
"\r\n" +
"Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.\r\n" +
"\r\n" +
"Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.")
@ArgumentNames({ "attributeLocator" })
@Deprecated
public String getElementAttribute(String attributeLocator) {
String[] parts = parseAttributeLocator(attributeLocator);
@RobotKeywordOverload
public String getElementAttribute(String locator) {
String[] parts = parseAttributeLocator(locator);
return getElementAttribute(parts[0], parts[1]);
}

Expand All @@ -444,14 +433,15 @@ public String getElementAttribute(String attributeLocator) {
"Example: ${id}= Get Element Attribute css:h1 id\r\n" +
"\r\n" +
"Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.")
@ArgumentNames({ "locator", "attribute" })
public String getElementAttribute(String locator, String attribute) {
@ArgumentNames({ "locator", "attribute=None" })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My approach:
@ArgumentNames({ "locator", "attribute=None" })
public String getElementAttribute(String locator, String... attribute) {
String attribute= robot.getParamsValue(attribute, 0, "None");

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this but for some reason it wouldn't except both the version with 1 parameter and the version with 2 parameters that way. That would only work with just the String... params parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait, serves me right, trying to answer stuff like this without access to the code... See the fix below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, great

public String getElementAttribute(String locator, String... attribute) {
String attributeName = robot.getParamsValue(attribute, 0, "None");
List<WebElement> elements = elementFind(locator, true, false);

if (elements.size() == 0) {
throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", locator));
}
return elements.get(0).getAttribute(attribute);
return elements.get(0).getAttribute(attributeName);
}

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