List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfAllElementsLocatedBy
public static ExpectedCondition<List<WebElement>> presenceOfAllElementsLocatedBy(final By locator)
From source file:com.xwikisas.xcs.test.po.tour.XCSPageWithTour.java
License:Open Source License
@Override public void end() { getDriver().findElement(By.xpath("//div[contains(@class, 'popover-navigation')]//button[@data-role='end']")) .click();/*from www.ja va 2s . c o m*/ getDriver().waitUntilCondition( ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("tour")))); }
From source file:com.xwikisas.xcs.test.po.tour.XCSPageWithTour.java
License:Open Source License
@Override public void close() { getDriver().findElement(By.xpath("//button[@data-role='end' and contains(@class, 'btn-default')]")).click(); getDriver().waitUntilCondition(//w w w. ja v a 2 s . co m ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("tour")))); }
From source file:de.knowwe.uitest.UITestUtils.java
License:Open Source License
private static boolean pageExists(WikiTemplate template, WebDriver driver) { if (template == haddock) { try {//w w w .java 2s. com new WebDriverWait(driver, 5) .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("a.createpage"))); } catch (Exception e) { // Element not present } return driver.findElements(By.cssSelector("a.createpage")).isEmpty(); } else { try { new WebDriverWait(driver, 5).until( ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("div.information a"))); } catch (Exception e) { // Element not present } return driver.findElements(By.cssSelector("div.information a")).stream() .noneMatch(webElement -> Strings.containsIgnoreCase(webElement.getText(), "create it")); } }
From source file:de.knowwe.uitest.UITestUtils.java
License:Open Source License
public static void enterArticleText(String newText, WebDriver driver, WikiTemplate template) { String areaSelector = template == WikiTemplate.haddock ? ".editor.form-control" : "#editorarea"; List<WebElement> editorAreas = new WebDriverWait(driver, 10) .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector(areaSelector))); if (driver instanceof JavascriptExecutor) { // hacky but fast/instant! ((JavascriptExecutor) driver).executeScript("var areas = document.querySelectorAll('" + areaSelector + "');" + "for (var i=0; i<areas.length; i++) { areas[i].value = arguments[0] };", newText); } else {// w w w. j a va2 s . c o m // sets the keys one by one, pretty slow... editorAreas.forEach(WebElement::clear); editorAreas.forEach(webElement -> webElement.sendKeys(newText)); } driver.findElement(By.name("ok")).click(); }
From source file:io.selendroid.webviewdrivertests.CookieHandlerTest.java
License:Apache License
private void setupWebView() { openWebdriverTestPage(HtmlTestData.ACTUAL_XHTML_PAGE); ((JavascriptExecutor) driver()).executeScript("window.location = 'http://www.google.com'"); new WebDriverWait(driver(), 10) .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("input[name=q]"))); }
From source file:javax.portlet.tck.driver.TCKSimpleTestDriver.java
License:Apache License
/** * Looks for a link or button that can be clicked for the TC and clicks it if found. * //from w ww.j ava 2s . com * First looks for a test case setup link or button and clicks it if found. Then it * looks for a test case execution link and clicks it if found. * * @return web element list containing the test case results. * @throws Exception */ @SuppressWarnings("unused") protected List<WebElement> processClickable(List<WebElement> wels) throws Exception { String setupId = tcName + Constants.SETUP_ID; String actionId = tcName + Constants.CLICK_ID; String resultId = tcName + Constants.RESULT_ID; String detailId = tcName + Constants.DETAIL_ID; String asyncId = tcName + Constants.ASYNC_ID; String notreadyId = tcName + Constants.NOTREADY_ID; List<WebElement> tcels = null; for (WebElement wel : wels) { tcels = wel.findElements(By.id(setupId)); if (!tcels.isEmpty()) break; } debugLines.add(" Setup link found: " + ((tcels != null) && !tcels.isEmpty())); // If were dealing with async, make sure the JavaScript is initialized List<WebElement> acels = driver.findElements(By.id(asyncId)); debugLines.add(" Async elements found: " + ((acels != null) && !acels.isEmpty())); if (acels != null && !acels.isEmpty()) { WebDriverWait wdw = new WebDriverWait(driver, timeout); wdw.until(ExpectedConditions.invisibilityOfElementLocated(By.id(notreadyId))); debugLines.add(" Async elements are now ready."); } // Click setup link if found if ((tcels != null) && !tcels.isEmpty()) { WebElement wel = tcels.get(0); if (scroll) { JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; javascriptExecutor.executeScript( "window.scrollTo(0, (arguments[0].getBoundingClientRect().top + window.pageYOffset) - (window.innerHeight / 2));", wel); } wel.click(); debugLines.add(" Clicked setup link."); WebDriverWait wdw = new WebDriverWait(driver, timeout); String expr = "//*[@id='" + resultId + "'] | //*[@id='" + actionId + "']"; debugLines.add(" xpath string: ===" + expr + "==="); wdw.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(expr))); wels = driver.findElements(By.name(tcName)); debugLines.add(" Found elements: " + (!wels.isEmpty())); List<WebElement> xels = driver.findElements(By.xpath(expr)); for (WebElement w : xels) { debugLines.add(" Element: " + w.getTagName() + ", id=" + w.getAttribute("id")); } } // Now click the action link, if present for (WebElement wel : wels) { tcels = wel.findElements(By.id(actionId)); if (!tcels.isEmpty()) break; } debugLines.add(" Clickable link found: " + ((tcels != null) && !tcels.isEmpty())); if (tcels != null && !tcels.isEmpty()) { WebElement wel = tcels.get(0); if (scroll) { JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; javascriptExecutor.executeScript( "window.scrollTo(0, (arguments[0].getBoundingClientRect().top + window.pageYOffset) - (window.innerHeight / 2));", wel); } wel.click(); WebDriverWait wdw = new WebDriverWait(driver, timeout); wdw.until(ExpectedConditions.visibilityOfElementLocated(By.id(resultId))); wels = driver.findElements(By.name(tcName)); if ((wels == null) || wels.isEmpty()) { throw new Exception("Test case " + tcName + " failed. No results after action link click."); } } return wels; }
From source file:javax.portlet.tck.driver.TCKTestDriver.java
License:Apache License
/** * Looks for a link or button that can be clicked for the TC and clicks it if found. * //from w w w .j a va2s . com * First looks for a test case setup link or button and clicks it if found. Then it * looks for a test case execution link and clicks it if found. * * @return web element list containing the test case results. * @throws Exception */ @SuppressWarnings("unused") protected List<WebElement> processClickable(List<WebElement> wels) throws Exception { String setupId = tcName + Constants.SETUP_ID; String actionId = tcName + Constants.CLICK_ID; String resultId = tcName + Constants.RESULT_ID; String detailId = tcName + Constants.DETAIL_ID; String asyncId = tcName + Constants.ASYNC_ID; String notreadyId = tcName + Constants.NOTREADY_ID; List<WebElement> tcels = null; for (WebElement wel : wels) { tcels = wel.findElements(By.id(setupId)); if (!tcels.isEmpty()) break; } debugLines.add(" Setup link found: " + ((tcels != null) && !tcels.isEmpty())); // If were dealing with async, make sure the JavaScript is initialized List<WebElement> acels = driver.findElements(By.id(asyncId)); debugLines.add(" Async elements found: " + ((acels != null) && !acels.isEmpty())); if (acels != null && !acels.isEmpty()) { WebDriverWait wdw = new WebDriverWait(driver, timeout); wdw.until(ExpectedConditions.invisibilityOfElementLocated(By.id(notreadyId))); debugLines.add(" Async elements are now ready."); } // Click setup link if found if ((tcels != null) && !tcels.isEmpty()) { WebElement wel = tcels.get(0); if (scroll) { JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; javascriptExecutor.executeScript( "window.scrollTo(0, (arguments[0].getBoundingClientRect().top + window.pageYOffset) - (window.innerHeight / 2));", wel); } try { wel.click(); } catch (StaleElementReferenceException e) { System.out.println("setup link: " + e.getClass().getName() + " caught when trying to use WebElements found with " + tcName); wels = driver.findElements(By.name(tcName)); for (WebElement welly : wels) { tcels = welly.findElements(By.id(setupId)); if (!tcels.isEmpty()) break; } wel = tcels.get(0); wel.click(); } debugLines.add(" Clicked setup link."); WebDriverWait wdw = new WebDriverWait(driver, timeout); String expr = "//*[@id='" + resultId + "'] | //*[@id='" + actionId + "']"; debugLines.add(" xpath string: ===" + expr + "==="); wdw.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(expr))); wels = driver.findElements(By.name(tcName)); debugLines.add(" Found elements: " + (!wels.isEmpty())); List<WebElement> xels = driver.findElements(By.xpath(expr)); for (WebElement w : xels) { debugLines.add(" Element: " + w.getTagName() + ", id=" + w.getAttribute("id")); } } // Now click the action link, if present for (WebElement wel : wels) { tcels = wel.findElements(By.id(actionId)); if (!tcels.isEmpty()) break; } debugLines.add(" Clickable link found: " + ((tcels != null) && !tcels.isEmpty())); if (tcels != null && !tcels.isEmpty()) { WebElement wel = tcels.get(0); if (scroll) { JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver; javascriptExecutor.executeScript( "window.scrollTo(0, (arguments[0].getBoundingClientRect().top + window.pageYOffset) - (window.innerHeight / 2));", wel); } try { wel.click(); } catch (StaleElementReferenceException e) { System.out.println("action link: " + e.getClass().getName() + " caught when trying to use WebElements found with " + tcName); wels = driver.findElements(By.name(tcName)); for (WebElement welly : wels) { tcels = welly.findElements(By.id(actionId)); if (!tcels.isEmpty()) break; } wel = tcels.get(0); wel.click(); } WebDriverWait wdw = new WebDriverWait(driver, timeout); wdw.until(ExpectedConditions.visibilityOfElementLocated(By.id(resultId))); wels = driver.findElements(By.name(tcName)); if ((wels == null) || wels.isEmpty()) { throw new Exception("Test case " + tcName + " failed. No results after action link click."); } } return wels; }
From source file:jhc.redsniff.webdriver.ExtraExpectedConditions.java
License:Apache License
/** * An expectation for checking that an element is present on the DOM of a * page and satisfies the supplied {@link Matcher} * @param locator//from www .java 2 s . c o m * @param matcher * @return */ public static ExpectedCondition<Boolean> elementsLocated(final By locator, final Matcher<Iterable<WebElement>> matcher) { return new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver input) { return matcher.matches(ExpectedConditions.presenceOfAllElementsLocatedBy(locator)); } @Override public String toString() { return new StringDescription().appendText("Element located by " + locator + " is ") .appendDescriptionOf(matcher).toString(); } }; }
From source file:org.alfresco.po.PageElement.java
License:Open Source License
/** * Wait until the visibility of given Element for given seconds. * // ww w.j av a2 s .c om * @param locator CSS Locator * @param timeOutInSeconds Timeout In Seconds */ public void waitUntilElementPresent(By locator, long timeOutInSeconds) { if (locator == null) { throw new IllegalArgumentException(LOCATOR_REQUIRED_ERR_MSG); } WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(locator)); }
From source file:org.alfresco.po.RenderElement.java
License:Open Source License
/** * Wait until the visibility of given Element for given seconds. * /* w w w. j a v a 2 s . c om*/ * @param driver WebDriver * @param locator CSS Locator * @param timeOutInSeconds Timeout In Seconds */ public void waitUntilElementPresent(WebDriver driver, By locator, long timeOutInSeconds) { if (locator == null) { throw new IllegalArgumentException(LOCATOR_REQUIRED_ERR_MSG); } WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(locator)); }