List of usage examples for org.openqa.selenium By toString
@Override
public String toString()
From source file:com.hotwire.test.steps.seo.SeoModelWebApp.java
License:Open Source License
private void waitForElementToBeVisible(final By locator) { new WebDriverWait(webdriver, DEFAULT_WAIT_TIME).until(new ExpectedCondition<Boolean>() { @Override//from w ww . j av a 2 s.c o m public Boolean apply(WebDriver webdriver) { boolean isDisplayed = webdriver.findElement(locator).isDisplayed(); LOGGER.info("Is '" + locator.toString() + "' displayed: " + isDisplayed); return isDisplayed; } }); }
From source file:com.liferay.faces.test.selenium.WebDriverMockImpl.java
License:Open Source License
@Override public WebElement findElement(By by) { if (!(by instanceof By.ByXPath)) { throw new UnsupportedOperationException(); }/*from w w w .ja v a 2 s . co m*/ String tagName = by.toString().replaceAll("[^/]+//([a-zA-Z0-9_\\-:.]+)[\\s\\S]*", "$1"); WebElement webElement = webElements.get(tagName); if (webElement == null) { throw new NoSuchElementException(""); } return webElement; }
From source file:com.mengge.pagefactory.bys.ContentMappedBy.java
License:Apache License
@Override public String toString() { By defaultBy = map.get(ContentType.HTML_OR_DEFAULT); By nativeBy = map.get(ContentType.NATIVE_MOBILE_SPECIFIC); if (defaultBy.equals(nativeBy)) { return defaultBy.toString(); }// ww w . ja va 2 s .c o m return "Locator map: " + "\n" + "- native content: \"" + nativeBy.toString() + "\" \n" + "- html content: \"" + defaultBy.toString() + "\""; }
From source file:com.meschbach.onomate.tests.assembly.scenarios.OnomateAssembly.java
License:Apache License
private void waitOn(By selector) { try {// w w w. j av a2 s . co m WebDriverWait wait = new WebDriverWait(driver, 2); wait.until(ExpectedConditions.presenceOfElementLocated(selector)); } catch (TimeoutException te) { throw new WaitTimeoutException("Unable to locate " + selector.toString(), te); } }
From source file:com.partnet.automation.HtmlView.java
License:Apache License
/** * Overloaded method to handle the various cases of switching to a window. * //from www .j a v a2s . c o m * @param element * - the element that should be searched for on the page, or * <code>null</code> * @param locator * - the locator that should be present on the page, or * <code>null</code> * @param pageTitle * - the title of the page to be switched to, or <code>null</code> * @param findNewWindow * - whether or not to find a new (true) or existing (false) window. * * @throws IllegalStateException * @throws TimeoutException */ private void switchToWindow(WebElement element, By locator, String pageTitle, boolean findNewWindow) throws IllegalStateException, TimeoutException { LOG.debug("Switch to correct window"); // at least one of the window-identifying parameters must be provided if (element == null && pageTitle == null && locator == null) { throw new IllegalArgumentException( "element, locator, and pageTitle are all null - cannot determine the correct window"); } // sanity check to ensure multiple window-identifying parameters are not // provided if (element != null && locator != null) { throw new IllegalArgumentException("element and locator cannot both be used to identify window"); } WebDriverWait wait = new WebDriverWait(webDriver, 15); // TODO: Nov 13, 2014 (fpedroza) - this logic is flawed as it assumes only 2 // windows will be open at a time int windowsToWaitFor = findNewWindow ? 2 : 1; // wait for the specified number of windows to be open wait.until(new MultipleWindowHandlesVisibleCondition(windowsToWaitFor)); Set<String> windowHandles = webDriver.getWindowHandles(); LOG.debug("Window handles: {}", windowHandles); // try all windows, because I don't know if the current focused window // correct, or if it is a different one for (String window : windowHandles) { LOG.debug("Switch to window '{}'", window); webDriver.switchTo().window(window); // wait for switched to window to load, because it still could be in the // process of loading when switching to it waitForPageToLoad(); try { // Now see if the now focused page has a element that is specific to // this page on it. if (element != null) { element.isDisplayed(); LOG.debug("Found web element on page!"); } if (locator != null) { webDriver.findElement(locator).isDisplayed(); LOG.debug("Found By locator on page!"); } } catch (NoSuchElementException e) { LOG.debug("Nope, try again. Msg: {}", e.getMessage().substring(0, e.getMessage().indexOf("\n"))); continue; } // optionally check that the page title is correct (if one was provided) if (pageTitle != null) { String currentPageTitle = webDriver.getTitle(); if (currentPageTitle.equals(pageTitle)) { LOG.debug("Found correct page title!"); return; } else { LOG.debug("Found window title of '{}' but searching for '{}' - continue", pageTitle, currentPageTitle); continue; } } // no additional check need so we're done return; } // if we make it here, the expected page wasn't found so report the error throw new IllegalStateException( String.format("Can not find the '%s' page with the element '%s' in the set of window handles!", pageTitle, element == null ? locator.toString() : element.toString())); }
From source file:com.partnet.automation.page.Page.java
License:Apache License
/** * Verifies existence of an element on the browser page using * <code>WebDriver.By</code> as defined by the Page object used in a step * class.//ww w . j av a 2 s . c o m * <p> * All <code>WebDriver.By</code> searches are valid including: id, css, * linkText, name, etc. * * @param by * - locator to use to locate expected page element * @throws IllegalStateException * - thrown if the page could not be verified * @see #verify() */ protected final void verifyBySelector(By by) throws IllegalStateException { if (webDriver.findElements(by).isEmpty()) { throw new IllegalStateException(String.format( "\nERROR - The page in the browser does not match the page class being used in the step class.\n" + "The element '%s' on the browser page was not found.\n\n", by.toString())); } }
From source file:com.pearson.uitest.helper.CommonHelper.java
public static By getLocatorFormatInt(By locator, int index) { String xpath = String.format(locator.toString(), "" + index); String newXpath = xpath.substring(xpath.indexOf('/')); return By.xpath(newXpath); }
From source file:com.pearson.uitest.helper.CommonHelper.java
public static By getLocatorFormatString(By locator, String sub) { String xpath = String.format(locator.toString(), "" + sub); String newXpath = xpath.substring(xpath.indexOf('/')); return By.xpath(newXpath); }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method works as a wrapper for findElement method of WebDriver. * So, in same cases, we may have the issue 'Stale Element Reference', i.e., * the element is not ready in DOM. Hence, to prevent exception, we develop * a function that is the same of findElement but avoid this exception. * * @param driver/*from ww w .ja v a2 s . co m*/ * @param locator * @return */ public WebElement FindElementInvisible(WebDriver driver, By locator, Integer timeout, final Integer pollingTime) { this.log.debug("FindElementInvisible::Enter"); this.log.debug("Locator: " + locator.toString()); WebElement element = null; ExecutorService executor = null; RunnableFindElementInvisible r = new RunnableFindElementInvisible(driver, timeout, pollingTime, locator); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); try { executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); element = r.getInvisbleElement(); } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded! Looking for: " + locator.toString()); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded! Looking for: " + locator.toString()); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.log.debug("FindElementInvisible::Exit"); return element; }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * * @param driver//from w w w .j a v a2s .c o m * @param locator * @return */ public String GetTextElementInvisible(WebDriver driver, By locator) { this.log.debug("GetTextElementInvisible::Enter"); this.log.debug("Locator: " + locator.toString()); String text = ""; try { WebElement element = FindElementInvisible(driver, locator); text = ((JavascriptExecutor) driver).executeScript("return arguments[0].textContent", element) .toString(); } catch (StaleElementReferenceException e) { this.log.warn("Stale Element Reference Exception"); text = FindElementInvisible(driver, locator).getText(); } catch (Exception e) { this.log.catching(e); } this.log.debug("GetTextElementInvisible::Exit"); return text; }