diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java index 1c0a2b6..eaf730c 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java @@ -437,6 +437,17 @@ public String getElementAttribute(String attributeLocator) { return getElementAttribute(parts[0], parts[1]); } + @RobotKeyword("Get the value of a given CSS property.") + @ArgumentNames({ "attribute", "locator" }) + public String getCssValue(final String attribute, final String locator) { + List elements = elementFind(locator, true, false); + + if (elements.size() == 0) { + throw new SeleniumLibraryNonFatalException(String.format("Element '%s' not found.", locator)); + } + return elements.get(0).getCssValue(attribute); + } + @RobotKeyword("Returns value of attribute from element locator.\r\n" + "\r\n" + "See the `Locating elements` section for details about the locator syntax.\r\n" + @@ -998,11 +1009,7 @@ protected boolean isEnabled(String locator) { return false; } String readonly = element.getAttribute("readonly"); - if (readonly != null && (readonly.equals("readonly") || readonly.equals("true"))) { - return false; - } - - return true; + return readonly == null || (!readonly.equals("readonly") && !readonly.equals("true")); } protected boolean isFocused(String locator) { @@ -1123,6 +1130,7 @@ protected CharSequence mapAsciiKeyCodeToKey(int keyCode) { case 127: return Keys.DELETE; default: + //noinspection NewStringBufferWithCharArgument return new StringBuffer((char) keyCode); } } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java index e8a735c..8471dd3 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java @@ -303,6 +303,26 @@ public void waitUntilTitleContains(final String title, String...params) { }); } + @RobotKeyword("Waits until the current WebElement attribute or CSS property will be containing value.") + @ArgumentNames({ "value", "attribute", "locator", "timeout=NONE", "message=NONE" }) + public void waitUntilElementAttributeValueContains(final String value, final String attribute, final String locator, String...params) { + String timeout = robot.getParamsValue(params, 0, null); + String message = robot.getParamsValue(params, 1, null); + if (message == null) { + message = String.format("Attribute value '%s' did not contain in attribute '%s' in ", value, attribute); + } + waitUntil( + timeout, + message, + () -> { + String currentValue = element.getElementAttribute(locator, attribute); + if (currentValue == null || currentValue.isEmpty()) { + currentValue = element.getCssValue(attribute, locator); + } + return value.equals(currentValue); + }); + } + @RobotKeyword("Waits until the current page title does not contain ``title``.\r\n" + "\r\n" + "Fails, if the timeout expires, before the page title does not contain the given title. \r\n" + diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java index 02ec4ed..a75d947 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java @@ -94,11 +94,11 @@ protected static List parseTableLocator(String tableLocator, String loca List locatorSuffixes = locatorSuffixesMap.get(tableLocatorType + locationMethod); - List parsedTabeLocators = new ArrayList<>(); + List parsedTableLocators = new ArrayList<>(); for (String locatorSuffix : locatorSuffixes) { - parsedTabeLocators.add(tableLocator + locatorSuffix); + parsedTableLocators.add(tableLocator + locatorSuffix); } - return parsedTabeLocators; + return parsedTableLocators; } protected static WebElement searchInLocators(WebDriver webDriver, List locators, String content) { diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Robotframework.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Robotframework.java index 65ff213..e161987 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Robotframework.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Robotframework.java @@ -96,7 +96,7 @@ public static String commonPath(String p1, String p2) { } public static String secsToTimestr(double double_secs) { - TimestrHelper secsToTimestrHelper = new TimestrHelper(double_secs); + TimeStringHelper secsToTimestrHelper = new TimeStringHelper(double_secs); return secsToTimestrHelper.getValue(); } @@ -117,7 +117,7 @@ public static double timestrToSecs(String timestr) { int mins = 0; int hours = 0; int days = 0; - int sign = 0; + int sign; if (timestr.charAt(0) == '-') { sign = -1; timestr = timestr.substring(1); diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimestrHelper.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimeStringHelper.java similarity index 89% rename from src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimestrHelper.java rename to src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimeStringHelper.java index 85b2bdb..6cb972f 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimestrHelper.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/TimeStringHelper.java @@ -3,10 +3,10 @@ import java.util.ArrayList; import java.util.List; -public class TimestrHelper { +public class TimeStringHelper { protected boolean compact; - protected List ret = new ArrayList(); + protected List ret = new ArrayList<>(); protected String sign; protected int millis; protected int secs; @@ -14,11 +14,11 @@ public class TimestrHelper { protected int hours; protected int days; - public TimestrHelper(double double_secs) { + public TimeStringHelper(double double_secs) { this(double_secs, false); } - public TimestrHelper(double double_secs, boolean compact) { + public TimeStringHelper(double double_secs, boolean compact) { this.compact = compact; secsToComponents(double_secs); addItem(days, "d", "day");