Java Code Examples for org.openqa.selenium.WebElement#toString()

The following examples show how to use org.openqa.selenium.WebElement#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that tries to click an element and
 * returns false if the click failed.
 */
public static ExpectedCondition<Boolean> elementWasClicked(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                element.click();
                return true;
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        public String toString() {
            return "element to be clicked: " + element.toString();
        }
    };
}
 
Example 2
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that waits until an element becomes
 * the active (in-focus) element.
 */
public static ExpectedCondition<Boolean> elementToBeActive(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                if (element.equals((driver.switchTo().activeElement()))) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        public String toString() {
            return "element to be active (in focus): " + element.toString();
        }
    };
}
 
Example 3
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that waits until an element becomes
 * disabled (generally applies to input elements).
 */
public static ExpectedCondition<Boolean> elementToBeDisabled(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                if (!element.isEnabled()) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        public String toString() {
            return "element to be disabled: " + element.toString();
        }
    };
}
 
Example 4
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that waits until an element becomes
 * enabled (generally applies to input elements).
 */
public static ExpectedCondition<Boolean> elementToBeEnabled(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                if (element.isEnabled()) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        public String toString() {
            return "element to be enabled: " + element.toString();
        }
    };
}
 
Example 5
Source File: CustomConditions.java    From opentest with MIT License 6 votes vote down vote up
/**
 * Returns an ExpectedCondition instance that waits until an element is not
 * active (in focus).
 */
public static ExpectedCondition<Boolean> elementToNotBeActive(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                if (!element.equals((driver.switchTo().activeElement()))) {
                    return true;
                } else {
                    return false;
                }
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        public String toString() {
            return "element to not be active (in focus): " + element.toString();
        }
    };
}