Search in sources :

Example 1 with Wait

use of org.openqa.selenium.support.ui.Wait in project carina by qaprosoft.

the class DriverHelper method findExtendedWebElement.

/**
 * Find Extended Web Element on page using By.
 *
 * @param by
 *            Selenium By locator
 * @param name
 *            Element name
 * @param timeout
 *            Timeout to find
 * @return ExtendedWebElement if exists otherwise null.
 */
public ExtendedWebElement findExtendedWebElement(final By by, String name, long timeout) {
    ExtendedWebElement element;
    final WebDriver drv = getDriver();
    wait = new WebDriverWait(drv, timeout, RETRY_TIME);
    try {
        setImplicitTimeout(0);
        wait.until((Function<WebDriver, Object>) dr -> !drv.findElements(by).isEmpty());
        element = new ExtendedWebElement(driver.findElement(by), name, by, driver);
        Messager.ELEMENT_FOUND.info(name);
    } catch (Exception e) {
        element = null;
        Messager.ELEMENT_NOT_FOUND.error(name);
        throw new RuntimeException(e);
    } finally {
        setImplicitTimeout(IMPLICIT_TIMEOUT);
    }
    return element;
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Wait(org.openqa.selenium.support.ui.Wait) SpecialKeywords(com.qaprosoft.carina.core.foundation.commons.SpecialKeywords) Parameter(com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter) Messager(com.qaprosoft.carina.core.foundation.utils.Messager) Set(java.util.Set) Configuration(com.qaprosoft.carina.core.foundation.utils.Configuration) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) Action(org.openqa.selenium.interactions.Action) Function(java.util.function.Function) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Logger(org.apache.log4j.Logger) BaseMatcher(org.hamcrest.BaseMatcher) List(java.util.List) CommonUtils(com.qaprosoft.carina.core.foundation.utils.common.CommonUtils) Matcher(java.util.regex.Matcher) CryptoTool(com.qaprosoft.carina.core.foundation.crypto.CryptoTool) AbstractPage(com.qaprosoft.carina.core.gui.AbstractPage) DevicePool(com.qaprosoft.carina.core.foundation.webdriver.device.DevicePool) Pattern(java.util.regex.Pattern) org.openqa.selenium(org.openqa.selenium) Actions(org.openqa.selenium.interactions.Actions) LogicUtils(com.qaprosoft.carina.core.foundation.utils.LogicUtils) ExtendedWebElement(com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 2 with Wait

use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.

the class Waiter method waitForElementTextContainsString.

/**
 * Method that waits for the text on the element to contain an expected String.
 * Checks whether the value resulted from getText() on the element contains the expected String.
 * Will wait for up to the specifiedTimeout number of seconds for the text on the element to contain the expected one.
 *
 * @param element          - the WebElement whose text will be checked
 * @param expectedString   - the value expected to be contained in the WebElement's text
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementTextContainsString(WebElement element, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementTextContainsString = arg0 -> element.getText().contains(expectedString);
    wait.until(elementTextContainsString);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 3 with Wait

use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.

the class Waiter method waitForElementAttributeEqualsString.

/**
 * Method that waits for an element's specified attribute's value to equal another specified String.
 * Compares the value resulted from getAttribute(nameOfAttribute) on the element with the expected String.
 * Will wait for up to the specified number of seconds for an element's attribute value to equal an expected String.
 *
 * @param element          - the WebElement whose attribute we are interested in
 * @param attribute        - the attribute whose value needs to be compared to another value
 * @param expectedString   - the expected value of the WebElement's attribute
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementAttributeEqualsString(WebElement element, String attribute, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementAttributeEqualsString = arg0 -> element.getAttribute(attribute).equals(expectedString);
    wait.until(elementAttributeEqualsString);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 4 with Wait

use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.

the class Waiter method click.

/**
 * Try to click on an element during the specifiedTimeout number of seconds.
 *
 * @param element          - the element to click on
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void click(WebElement element, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementIsClickable = arg0 -> {
        try {
            element.click();
            return true;
        } catch (Exception e) {
            return false;
        }
    };
    wait.until(elementIsClickable);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 5 with Wait

use of org.openqa.selenium.support.ui.Wait in project thewaiter by iamalittletester.

the class Waiter method waitForElementAttributeContainsString_IgnoreCase.

/**
 * Method that waits for an element's specified attribute's value to contain another specified String, no matter
 * the case of the actual or expected value.
 * Compares the value resulted from getAttribute(nameOfAttribute) on the element with the expected String,
 * ignoring the cases.
 * Will wait for up to the specifiedTimeout number of seconds for the expected condition to occur.
 *
 * @param element          - the WebElement whose attribute we are interested in
 * @param attribute        - the attribute whose value needs to be compared to another value
 * @param expectedString   - the expected value of the WebElement's attribute, case insensitive
 * @param driver           - the WebDriver instance
 * @param specifiedTimeout - amount of seconds you want to wait for
 */
public void waitForElementAttributeContainsString_IgnoreCase(WebElement element, String attribute, String expectedString, WebDriver driver, int specifiedTimeout) {
    WebDriverWait wait = new WebDriverWait(driver, specifiedTimeout);
    ExpectedCondition<Boolean> elementAttributeContainsStringIC = arg0 -> element.getAttribute(attribute).toLowerCase().contains(expectedString.toLowerCase());
    wait.until(elementAttributeContainsStringIC);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) Wait(org.openqa.selenium.support.ui.Wait) WebDriver(org.openqa.selenium.WebDriver) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Aggregations

Wait (org.openqa.selenium.support.ui.Wait)29 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)27 WebDriver (org.openqa.selenium.WebDriver)23 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)22 WebElement (org.openqa.selenium.WebElement)22 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)22 Function (java.util.function.Function)9 TimeoutException (org.openqa.selenium.TimeoutException)7 SpecialKeywords (com.qaprosoft.carina.core.foundation.commons.SpecialKeywords)6 CryptoTool (com.qaprosoft.carina.core.foundation.crypto.CryptoTool)6 Configuration (com.qaprosoft.carina.core.foundation.utils.Configuration)6 Parameter (com.qaprosoft.carina.core.foundation.utils.Configuration.Parameter)6 LogicUtils (com.qaprosoft.carina.core.foundation.utils.LogicUtils)6 Messager (com.qaprosoft.carina.core.foundation.utils.Messager)6 CommonUtils (com.qaprosoft.carina.core.foundation.utils.common.CommonUtils)6 ExtendedWebElement (com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement)6 AbstractPage (com.qaprosoft.carina.core.gui.AbstractPage)6 List (java.util.List)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6