List of usage examples for org.openqa.selenium.support.ui FluentWait until
@Override public <V> V until(Function<? super T, V> isTrue)
From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java
License:Open Source License
/** * @param by//from ww w .j a v a 2s .c om * @param text * @return */ public static void waitUntilElementContainsText(@NonNull final WebDriver driver, @NonNull final By by, @NonNull final String text, int timeout) { // Waiting for an element to be present on the page, checking for its // presence once every second. final FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS).ignoring(TimeoutException.class); wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver webDriver) { try { return webDriver.findElement(by).getText().contains(text); } catch (final StaleElementReferenceException e) { return false; } catch (final NoSuchElementException e) { return false; } } }); }
From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java
License:Open Source License
/** * @param by//from w ww . j av a 2 s. c o m * @return */ public static void waitUntilElementContainsAttribute(@NonNull final WebDriver driver, @NonNull final By by, @NonNull final String attribute) { // Waiting for an element to be present on the page, checking for its // presence once every second. final FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS).ignoring(TimeoutException.class); wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver webDriver) { try { return StringUtils.isNotEmpty(webDriver.findElement(by).getAttribute(attribute)); } catch (final StaleElementReferenceException e) { return false; } catch (final NoSuchElementException e) { return false; } } }); }
From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java
License:Open Source License
/** * @param text//from w w w .j av a2 s . co m */ public static void waitUntilTextIsSelected(@NonNull final WebDriver driver, @NonNull final By by, @NonNull final String text) { final FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); wait.until(new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver webDriver) { final WebElement webElement = webDriver.findElement(by); new Select(webElement).selectByVisibleText(text); return webElement; } }); }
From source file:com.worldline.easycukes.selenium.utils.SeleniumHelper.java
License:Open Source License
/** * @param by//from ww w . ja v a 2s .c om * @return */ public static void waitUntilValueIsSelected(@NonNull final WebDriver driver, @NonNull final By by, @NonNull final String value) { final FluentWait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(WAITING_TIME_OUT_IN_SECONDS, TimeUnit.SECONDS) .pollingEvery(POLLING_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); wait.until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver webDriver) { try { final WebElement webElement = webDriver.findElement(by); new Select(webElement).selectByValue(value); return webElement.getAttribute("value").equals(value); } catch (final StaleElementReferenceException e) { return false; } } }); }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.Pagination.PaginationHandler18.java
License:Apache License
public void processCheaperthandirt(WebDriver driver) { FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver); wait.until(new Predicate<WebDriver>() { public boolean apply(WebDriver driver) { return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete"); }//from w w w. ja va2 s . co m }); int size = driver .findElements( By.id("ctl00_ctl00_ContentPlaceHolderTopLevel_ContentPlaceHolderItemList_displayTopDDL")) .size(); if (size > 0) { Select dropdown = new Select(driver.findElement( By.id("ctl00_ctl00_ContentPlaceHolderTopLevel_ContentPlaceHolderItemList_displayTopDDL"))); dropdown.selectByVisibleText("Show All"); } }
From source file:io.appium.java_client.pagefactory.bys.builder.ByChained.java
License:Apache License
@Override public WebElement findElement(SearchContext context) { AppiumFunction<SearchContext, WebElement> searchingFunction = null; for (By by : bys) { searchingFunction = Optional .ofNullable(// w w w . jav a 2 s . c o m searchingFunction != null ? searchingFunction.andThen(getSearchingFunction(by)) : null) .orElse(getSearchingFunction(by)); } FluentWait<SearchContext> waiting = new FluentWait<>(context); try { checkNotNull(searchingFunction); return waiting.until(searchingFunction); } catch (TimeoutException e) { throw new NoSuchElementException("Cannot locate an element using " + toString()); } }
From source file:org.alfresco.demoamp.po.DemoPage.java
License:Open Source License
/** * Mechanism to keep looking for an element on the page. * @param by selector// ww w . j a va2s. c o m * @param limit max time to wait in ms * @param interval time to wait between calls in ms * @return */ public WebElement findAndWait(final By by, final long limit, final long interval) { FluentWait<By> fluentWait = new FluentWait<By>(by); fluentWait.pollingEvery(interval, TimeUnit.MILLISECONDS); fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS); fluentWait.until(new Predicate<By>() { public boolean apply(By by) { try { return driver.findElement(by).isDisplayed(); } catch (NoSuchElementException ex) { return false; } } }); return driver.findElement(by); }
From source file:org.alfresco.FetchTest.java
License:Open Source License
public WebElement findAndWait(final By by) { FluentWait<By> fluentWait = new FluentWait<By>(by); fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS); fluentWait.withTimeout(5000, TimeUnit.MILLISECONDS); try {/*from w w w . j a v a 2s . c o m*/ fluentWait.until(new Predicate<By>() { public boolean apply(By by) { try { return driver.findElement(by).isDisplayed(); } catch (NoSuchElementException ex) { return false; } } }); return driver.findElement(by); } catch (RuntimeException re) { throw new TimeoutException("Unable to locate element " + by); } }
From source file:org.alfresco.po.PageElement.java
License:Open Source License
/** * Verify if loading of the page is complete using java script to validate state of the HTML DOM. * //from w ww. ja v a 2 s . c o m * @param waitTime max time to look for an element * @return true if page has been loaded */ public boolean isRenderComplete(final long waitTime) { FluentWait<String> fluentWait = new FluentWait<String>("complete"); fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS); fluentWait.withTimeout(waitTime, TimeUnit.MILLISECONDS); try { fluentWait.until(new Predicate<String>() { @Override public boolean apply(String input) { String response = (String) executeJavaScript("return document.readyState;"); return response.equals(input); } }); return true; } catch (TimeoutException te) { } return false; }
From source file:org.alfresco.po.PageElement.java
License:Open Source License
/** * Helper method to find a {@link WebElement} with a time limit in milliseconds. During the wait period it will check for the element every 100 millisecond. * // w w w. j av a 2 s . c o m * @param by {@link By} criteria to search by * @param limit time limit * @param interval polling frequency * @return {@link WebElement} HTML element */ public WebElement findAndWait(final By by, final long limit, final long interval) { FluentWait<By> fluentWait = new FluentWait<By>(by); fluentWait.pollingEvery(interval, TimeUnit.MILLISECONDS); fluentWait.withTimeout(limit, TimeUnit.MILLISECONDS); try { fluentWait.until(new Predicate<By>() { public boolean apply(By by) { try { return driver.findElement(by).isDisplayed(); } catch (NoSuchElementException ex) { return false; } } }); return driver.findElement(by); } catch (RuntimeException re) { throw new TimeoutException("Unable to locate element " + by); } }