List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout)
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
/** * Mtodo que verifica em todas as classes se existe um componente Loading, * e se existir, ele sempre espera que este elemento desaparea antes de * continuar./* w w w . j ava 2 s . c o m*/ */ @SuppressWarnings("unchecked") public void waitLoading() { driver = (WebDriver) runner.getDriver(); driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); if (!alreadySearchLoadingMap) { alreadySearchLoadingMap = true; Reflections reflections = new Reflections(""); Set<Class<?>> annotatedClasses = reflections.getTypesAnnotatedWith(ScreenMap.class); for (Class<?> clazzI : annotatedClasses) { HashSet<Field> fields = (HashSet<Field>) ReflectionUtils.getAllFields(clazzI, ReflectionUtils.withAnnotation(ElementMap.class), ReflectionUtils.withTypeAssignableTo(Loading.class)); if (fields.size() == 1) { for (Field field : fields) { loadingMap = field.getAnnotation(ElementMap.class); } } } } if (loadingMap != null) { boolean existeLoading; try { // Verifica se existe o LOADING ExpectedConditions .presenceOfElementLocated( ByConverter.convert(loadingMap.locatorType(), loadingMap.locator()[0])) .apply(driver); existeLoading = true; log.debug(message.getString("message-loading-visible")); } catch (Exception e) { existeLoading = false; } if (existeLoading) { // Fora esperar o loading aparecer quando o elemento utilizado // tem a propriedade forWaitLoading na anotao @ElementMap if (getElementMap() != null && getElementMap().forceWaitLoading()) { WebDriverWait wait = new WebDriverWait(getDriver(), (BehaveConfig.getRunner_ScreenMaxWait() / 1000)); wait.until(ExpectedConditions.visibilityOfElementLocated( ByConverter.convert(loadingMap.locatorType(), loadingMap.locator()[0]))); log.debug(message.getString("message-force-loading")); } // Aguardo o LOADING desaparecer! WebDriverWait wait = new WebDriverWait(getDriver(), (BehaveConfig.getRunner_ScreenMaxWait() / 1000)); wait.until(ExpectedConditions.invisibilityOfElementLocated( ByConverter.convert(loadingMap.locatorType(), loadingMap.locator()[0]))); log.debug(message.getString("message-loading-invisible")); } } driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
private void waitClickable(By by) { findFrameContainingElement(by);/*w w w. j av a2s . c o m*/ // Faz a verificao no FRAME selecionado WebDriverWait wait = new WebDriverWait(getDriver(), (BehaveConfig.getRunner_ScreenMaxWait() / 1000)); wait.until(ExpectedConditions.elementToBeClickable(by)); }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
private void waitVisibility(By by) { findFrameContainingElement(by);/*ww w.ja v a 2s .c o m*/ WebDriverWait wait = new WebDriverWait(getDriver(), (BehaveConfig.getRunner_ScreenMaxWait() / 1000)); wait.until(ExpectedConditions.visibilityOfElementLocated(by)); }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebBase.java
License:Open Source License
public void waitInvisible(int index) { final String locator = getLocatorWithParameters(getElementMap().locator()[index].toString()); final By by = ByConverter.convert(getElementMap().locatorType(), locator); boolean testInvisibility = true; driver = (WebDriver) runner.getDriver(); // Zera o tempo do driver, se no o implicity wait no funciona com o // tempo correto driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); try {/*from w ww . j a v a 2 s .c om*/ // Aguarda o elemento ficar visivel (MinWait) Long waitTimeVis = (BehaveConfig.getRunner_ScreenMinWait() / 1000); WebDriverWait waitVis = new WebDriverWait(driver, waitTimeVis); waitVis.until(ExpectedConditions.visibilityOfElementLocated(by)); testInvisibility = true; } catch (org.openqa.selenium.TimeoutException e) { testInvisibility = false; } if (testInvisibility) { // Aguarda ele sumir Long waitTime = (BehaveConfig.getRunner_ScreenMaxWait() / 1000); WebDriverWait wait = new WebDriverWait(driver, waitTime); wait.until(ExpectedConditions.invisibilityOfElementLocated(by)); } // Volta o tempo padro (maxWait) no driver driver.manage().timeouts().implicitlyWait(BehaveConfig.getRunner_ScreenMaxWait(), TimeUnit.MILLISECONDS); }
From source file:br.ufmg.dcc.saotome.beholder.selenium.SeleniumBrowser.java
License:Apache License
@Override public boolean isTextPresent(final String text) { try {/*from w ww . j av a 2 s .c om*/ WebDriverWait wait = new WebDriverWait(SeleniumController.getDriver(), SeleniumComponent.TIMEOUT); ExpectedCondition<Boolean> resultsAreDisplayed = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver arg0) { String expression = text.toLowerCase(); String pageText = SeleniumController.getDriver().findElement(By.tagName("body")).getText() .toLowerCase(); return pageText.contains(expression); } }; wait.until(resultsAreDisplayed); return true; } catch (TimeoutException toe) { return false; } }
From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.form.SeleniumSelectField.java
License:Apache License
private void selectByType(final Type type, final Object value) { final Option option = new SeleniumOption(); switch (type) { case INDEX:/*from w ww . java 2 s. c om*/ option.setIndex((Integer) value); break; case VALUE: option.setValue((String) value); break; case TEXT: option.setText((String) value); break; } WebDriverWait wait = new WebDriverWait(getSeleniumWebDriver(), SeleniumComponent.TIMEOUT); ExpectedCondition<Option> resultsAreDisplayed = new ExpectedCondition<Option>() { public Option apply(WebDriver driver) { Iterator<Option> iterator = getOptions().iterator(); while (iterator.hasNext()) { Option opt = iterator.next(); if (isSame(option, opt)) { ((SeleniumOption) opt).webElement.click(); return opt; } } return null; } }; wait.until(resultsAreDisplayed); }
From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.SeleniumComponent.java
License:Apache License
@Override public void loadByAttribute(final String tagName, final String attributeName, final String value) { this.locator = new Locator(tagName, attributeName, value); if (this.isDisplayed) { WebDriverWait wait = new WebDriverWait(getSeleniumWebDriver(), TIMEOUT); ExpectedCondition<Boolean> resultsAreDisplayed = new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver arg0) { List<WebElement> elements = getSeleniumWebDriver().findElements(By.tagName(tagName)); for (WebElement el : elements) { if ((el.getAttribute(attributeName) != null) && (el.getAttribute(attributeName).equalsIgnoreCase(value))) { setAttribute(attributeName, value); setElement(el);/*from ww w . j a v a 2 s . c om*/ return true; } } return false; } }; wait.until(resultsAreDisplayed); } }
From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.SeleniumComponent.java
License:Apache License
@Override public <T extends Component, Y extends T> List<T> loadByAttribute(Class<Y> type, final String IdFather, final String tagName, final String attributeName, final String value) { List<T> components = new ArrayList<T>(); this.locator = new Locator(tagName, attributeName, value); if (this.isDisplayed) { WebDriverWait wait = new WebDriverWait(getSeleniumWebDriver(), TIMEOUT); wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.tagName(tagName))); List<WebElement> elements; if (IdFather == null) { elements = getSeleniumWebDriver().findElements(By.tagName(tagName)); } else {/* w w w .j a va 2s .co m*/ elements = getSeleniumWebDriver().findElement(By.id(IdFather)).findElements(By.tagName(tagName)); } for (WebElement el : elements) { if ((el.getAttribute(attributeName) != null) && (el.getAttribute(attributeName).equalsIgnoreCase(value))) { T sc = null; try { // Use of reflection for instantiate sc // this equivalent the get an instance of Builder.uiComponentBuilderInstance() sc = (T) type.getDeclaredConstructor(WebDriver.class).newInstance(getSeleniumWebDriver()); } catch (Exception e) { e.printStackTrace(); } ((SeleniumComponent) sc).setAttribute(attributeName, value); ((SeleniumComponent) sc).setElement(el); components.add(sc); } } } return components; }
From source file:br.ufmg.dcc.saotome.beholder.selenium.ui.SeleniumComponent.java
License:Apache License
@Override public void loadByXPath(final String value) { this.locator = new Locator(Locator.LocatorType.XPATH, value); if (this.isDisplayed) { WebDriverWait wait = new WebDriverWait(getSeleniumWebDriver(), TIMEOUT); wait.until(ExpectedConditions.visibilityOf(getSeleniumWebDriver().findElement(By.xpath(value)))); setXPath(value);//w ww. j a v a 2s. com setElement(getSeleniumWebDriver().findElement(By.xpath(value))); } }
From source file:budget.WebDriverManager.java
private static void refreshAccountsWF() { int attempts = 3; int attempt = 1; Boolean isDownloaded = false; List<String> credentials = getCredentials(4); while ((attempt <= attempts) && !isDownloaded) { try {//from ww w .ja v a 2 s . c o m driver = new HtmlUnitDriver(true); wait = new WebDriverWait(driver, timeout); java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit") .setLevel(java.util.logging.Level.OFF); java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF); driver.get("Http://www.wellsfargo.com"); driver.findElement(By.id("userid")).clear(); driver.findElement(By.id("userid")).sendKeys(credentials.get(0)); driver.findElement(By.id("password")).clear(); driver.findElement(By.id("password")).sendKeys(credentials.get(1)); driver.findElement(By.id("btnSignon")).click(); waitAndClick(driver, wait, By.xpath("//th[@id='cashAccount1']/a")); runQueryWF(driver, wait, 4); runQueryWF(driver, wait, 5); runQueryWF(driver, wait, 6); driver.findElement(By.linkText("Sign Off")).click(); driver.close(); driver.quit(); isDownloaded = true; } catch (Exception ex) { driver.quit(); trace(ex.getMessage(), taLog); clearBatch(stmt); attempt++; } ; } trace((isDownloaded ? "Downloaded" : "Not downloaded") + " from " + attempt + ((attempt == 1) ? " attempt" : " attemps"), taLog); executeBatch(stmt, taLog); }