List of usage examples for org.openqa.selenium By toString
@Override
public String toString()
From source file:com.atanas.kanchev.testframework.selenium.handlers.Finder.java
License:Apache License
private List<WebElement> findElements(By locator) { logger.debug("Locating elements using " + locator.toString()); try {/*from ww w. j a v a 2s. c o m*/ List<WebElement> e = driver.findElements(locator); int numberOfElementsFound = e.size(); if (numberOfElementsFound == 0) throw new NoSuchElementException("Elements found: " + numberOfElementsFound); logger.debug("Elements found: " + numberOfElementsFound); return e; } catch (NoSuchElementException nsee) { throw new NoSuchElementException("Unable to locate any elements using " + locator.toString(), nsee); } }
From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java
License:Apache License
/** * {@inheritDoc}// w w w . j a va2s. co m */ @Override public boolean isElementPresent(By locator, long wait) { try { getWait(wait).until(ExpectedConditions.presenceOfElementLocated(locator)); return true; } catch (TimeoutException e) { logger.error("Timeout after waiting for presence of element by: " + locator.toString()); throw new TimeoutException(e.getMessage()); } }
From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java
License:Apache License
/** * {@inheritDoc}/* w w w . j av a 2 s. com*/ */ @Override public boolean isElementVisible(By locator, boolean visibility, long wait) { if (visibility) try { getWait(wait).until(ExpectedConditions.visibilityOfElementLocated(locator)); return true; } catch (TimeoutException e) { logger.error( "Timeout after waiting " + wait + " for visibility of element by: " + locator.toString()); return false; } else try { getWait(wait).until(ExpectedConditions.invisibilityOfElementLocated(locator)); return true; } catch (TimeoutException e) { logger.error("Timeout after waiting " + wait + " for invisibility of element by: " + locator.toString()); throw new TimeoutException(e.getMessage()); } }
From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java
License:Apache License
/** * {@inheritDoc}/*from w ww . j a va2s.c o m*/ */ @Override public boolean isElementClickable(By locator, long wait) { try { getWait(wait).until(ExpectedConditions.elementToBeClickable(locator)); return true; } catch (TimeoutException e) { logger.error("Timeout after waiting for element to be clickable located by: " + locator.toString()); throw new TimeoutException(e.getMessage()); } }
From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java
License:Apache License
/** * {@inheritDoc}/*from ww w. ja va 2 s . c o m*/ */ @Override public boolean isTextPresentInElementValue(By locator, String text, long wait) { try { getWait(wait).until(ExpectedConditions.textToBePresentInElementValue(locator, text)); return true; } catch (TimeoutException e) { logger.error("Timeout after waiting text " + text + " to be present in element located by " + locator.toString()); throw new TimeoutException(e.getMessage()); } }
From source file:com.atanas.kanchev.testframework.selenium.handlers.Wait.java
License:Apache License
/** * {@inheritDoc}//from w w w . jav a2 s . c o m */ @Override public boolean isFrameAvailable(By locator, long wait) { try { getWait(wait).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(locator)); return true; } catch (NoSuchFrameException e) { logger.error("No frame found located by " + locator.toString()); throw new NoSuchFrameException(e.getMessage()); } }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method to find clickable element./*from w w w .j av a 2 s. co m*/ * * @param by * (by element) * @return (clickable element) */ public WebElement findClickableElement(final By by) { WebElement clickableElement; try { clickableElement = (new WebDriverWait(this.driver, this.DEFAULT_TIMEOUT)) .until(ExpectedConditions.elementToBeClickable(by)); } catch (Throwable cause) { String errorMessage = "Could not find clickable element: " + by.toString(); this.logger.logWithScreenShot("findClickableElement failed.", this.driver); throw new RuntimeException(errorMessage); } return clickableElement; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method to find presence of the element in page. * //from w ww . ja v a 2 s .co m * @param by * (by element to be visible in page) * @param timeoutInSeconds * (timeout value in seconds) * @return presenceOfElement (Web element object of the presence element) */ public WebElement findPresenceOfElement(final By by, final int timeoutInSeconds) { WebElement presenceOfElement; try { presenceOfElement = (new WebDriverWait(this.driver, timeoutInSeconds)) .until(ExpectedConditions.presenceOfElementLocated(by)); } catch (Exception e) { String errorMessage = "Could not find presence of element: " + by.toString(); this.logger.logWithScreenShot("Could not find presence of element: " + by.toString(), this.driver); throw new RuntimeException(errorMessage); } return presenceOfElement; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method to find presence of the elements in page. * /*w ww . j a va 2 s . com*/ * @param by * (by element to be visible in page) * @param timeoutInSeconds * (timeout value in seconds) * @return presenceOfElement (Web element object of the presence element) */ public List<WebElement> findPresenceOfElements(final By by, final int timeoutInSeconds) { List<WebElement> presenceOfElements; try { presenceOfElements = (new WebDriverWait(this.driver, timeoutInSeconds)) .until(ExpectedConditions.presenceOfAllElementsLocatedBy(by)); } catch (Exception e) { String errorMessage = "Could not find presence of elements: " + by.toString(); this.logger.logWithScreenShot("Could not find presence of elements: ", this.driver); throw new RuntimeException(errorMessage); } return presenceOfElements; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method to find presence of inner text for the elements in page. * Can be used when elements vissibiliy is changed dynamically to make sure * that inner text is vissible./*from w ww .ja v a 2 s. c om*/ * @param by * @param timeoutInSeconds * @return presenceOfElements */ public List<WebElement> findPresenceOfInnerTextForElements(final By by, final int timeoutInSeconds) { List<WebElement> presenceOfElements; final int waitForElement = timeoutInSeconds / 5; try { presenceOfElements = (new WebDriverWait(this.driver, timeoutInSeconds)) .until(new ExpectedCondition<List<WebElement>>() { @Override public List<WebElement> apply(WebDriver driver) { try { List<WebElement> elements = findPresenceOfElements(by, waitForElement); for (WebElement element : elements) { if (!StringUtils.hasText(element.getText())) { return null; } } return elements.size() > 0 ? elements : null; } catch (Throwable e) { return null; } } }); } catch (Exception e) { this.logger.logWithScreenShot("Could not find presence of elements: " + by.toString(), this.driver); throw new RuntimeException(e); } return presenceOfElements; }