List of usage examples for org.openqa.selenium By toString
@Override
public String toString()
From source file:org.auraframework.test.util.AuraUITestingUtil.java
License:Apache License
/** * Waits for element with matching locator to appear in dom. * /*from w w w . j a va 2 s. c o m*/ * Convenience routine to supply a message. * * @param locator By of element waiting for. */ public WebElement waitForElement(By locator) { String msg = "Element with locator \'" + locator.toString() + "\' never appeared"; return waitForElement(msg, locator); }
From source file:org.auraframework.test.util.AuraUITestingUtil.java
License:Apache License
/** * Find matching elements in the DOM./* www .j a v a 2 s. c o m*/ * * @param locator * @return */ public List<WebElement> findDomElements(final By locator) { WebDriverWait wait = new WebDriverWait(driver, timeoutInSecs); return wait.withMessage("fail to find element in dom:" + locator.toString()) .ignoring(StaleElementReferenceException.class).until(new ExpectedCondition<List<WebElement>>() { @Override public List<WebElement> apply(WebDriver d) { List<WebElement> elements = driver.findElements(locator); if (elements.size() > 0 && getBooleanEval("return arguments[0].ownerDocument === document", elements.get(0))) { return elements; } return null; } }); }
From source file:org.auraframework.test.util.WebDriverTestCase.java
License:Apache License
public void waitForElementAppear(By locator) { String msg = "Element with locator \'" + locator.toString() + "\' never appeared"; waitForElementAppear(msg, locator);//ww w . jav a2 s . co m }
From source file:org.auraframework.test.util.WebDriverTestCase.java
License:Apache License
public void waitForElementDisappear(By locator) { String msg = "Element with locator \'" + locator.toString() + "\' never disappeared"; waitForElementDisappear(msg, locator); }
From source file:org.bigtester.ate.model.page.elementfind.AbstractElementFind.java
License:Apache License
/** * Find through frames./*w w w.j a va2 s . co m*/ * * @param win * the win * @param winFrame * the win frame * @param wait * the wait * @param findByValue * the find by value * @return the web element */ @Nullable protected WebElement findThroughFrames(BrowserWindow win, WindowFrame winFrame, Wait<WebDriver> wait, final By findByValue) { win.getCurrentElementFindFrameChain().add(winFrame); winFrame.obtainFrameFocus(); WebElement retValWE = null;// NOPMD try { retValWE = wait.until( // NOPMD new Function<WebDriver, WebElement>() { public @Nullable WebElement apply( // NOPMD @Nullable WebDriver driver) { if (null == driver) { throw new IllegalStateException("webdriver is not correctly populated."); } else { List<WebElement> allElements = driver.findElements(findByValue); if (allElements.size() == 0) throw new NoSuchElementException(findByValue.toString()); WebElement retVal; int intIndex = getIndexOfSameElementsInt(); if (intIndex < -1) { retVal = allElements.get(0); } else if (intIndex == -1) { retVal = allElements.get(allElements.size() - 1); } else { retVal = allElements.get(intIndex); } return retVal; // return driver.findElement(findByValue); } } }); if (null != retValWE) { if (!win.getLastSuccessElementFindFrameChain().equals(win.getCurrentElementFindFrameChain())) { win.getLastSuccessElementFindFrameChain().clear(); win.getLastSuccessElementFindFrameChain().addAll(win.getCurrentElementFindFrameChain()); } } } catch (NoSuchElementException | TimeoutException error) { List<WindowFrame> childFrames = winFrame.getChildFrames(); for (WindowFrame gChildF : childFrames) { if (null == gChildF) throw GlobalUtils.createInternalError("java arraylist", error); retValWE = findThroughFrames(win, gChildF, wait, findByValue); if (null != retValWE) { break; } } } if (null == retValWE) { if (winFrame.getParentFrame() == null) { winFrame.focusDefautContent(); } else { winFrame.focusParentFrame(); } } return retValWE; }
From source file:org.bigtester.ate.model.page.elementfind.AbstractElementFind.java
License:Apache License
/** * Find element./*from w w w.ja va 2s . co m*/ * * @param findBy * the find by * @param myWebDriver * the my web driver * @return the web element */ protected WebElement findElement(final By findBy, IMyWebDriver myWebDriver) { WebDriver webD = myWebDriver.getWebDriver(); if (null == webD) { throw new IllegalStateException("web driver is not correctly populated."); } else { createWait(webD); BrowserWindow winOnFocus = myWebDriver.getMultiWindowsHandler().getBrowserWindowOnFocus(); winOnFocus.switchToDefaultContent(); if (!winOnFocus.getLastSuccessElementFindFrameChain().isEmpty()) { for (WindowFrame lastSuccessWFrame : winOnFocus.getLastSuccessElementFindFrameChain()) { lastSuccessWFrame.obtainFrameFocus(); } } WebElement retValWE = null;// NOPMD try { retValWE = getWait().until( // NOPMD new Function<WebDriver, WebElement>() { public @Nullable WebElement apply( // NOPMD @Nullable WebDriver driver) { if (null == driver) { throw new IllegalStateException("webdriver is not correctly populated."); } else { List<WebElement> allElements = driver.findElements(findBy); if (allElements.size() == 0) throw new NoSuchElementException(findByValue); WebElement retVal; int intIndex = getIndexOfSameElementsInt(); if (intIndex < -1) { retVal = allElements.get(0); } else if (intIndex == -1) { retVal = allElements.get(allElements.size() - 1); } else { retVal = allElements.get(intIndex); } return retVal; } } }); } catch (NoSuchElementException | TimeoutException error) { winOnFocus.getCurrentElementFindFrameChain().clear(); for (WindowFrame winfr : winOnFocus.getVisibleFrames()) { try { if (null == winfr) throw GlobalUtils.createInternalError("arraylist error", error); winfr.focusDefautContent(); retValWE = findThroughFrames(winOnFocus, winfr, getWait(), findBy); if (null == retValWE) winfr.focusDefautContent(); else { break; } } catch (NoSuchElementException | TimeoutException error1) { continue; } } } if (null != retValWE) { return retValWE; } throw new NoSuchElementException(findBy.toString()); } }
From source file:org.glassfish.tyrus.tests.qa.SeleniumToolkit.java
License:Open Source License
public void click(By by) throws Exception { WebElement el = driver.findElement(by); if (el == null) { throw new Exception("Can't find element: " + by.toString()); }/*from w w w . j a va2 s .c om*/ Thread.sleep(sleepTime); takeScreenshot(driver); el.click(); }
From source file:org.glassfish.tyrus.tests.qa.SeleniumToolkit.java
License:Open Source License
public void sendKeys(By by, String text) throws InterruptedException, Exception { WebElement el = driver.findElement(by); if (el == null) { throw new Exception("Can't find element: " + by.toString()); }/*from ww w .j a va 2s .c o m*/ Thread.sleep(sleepTime); takeScreenshot(driver); el.clear(); el.sendKeys(text); }
From source file:org.kuali.rice.testtools.selenium.JiraAwareAftBase.java
License:Educational Community License
/** * {@see WebDriverUtils#findElement}./*w ww . j a v a2 s. c o m*/ * * @param by to find element with * @return WebElement found with given by */ protected WebElement findElement(By by) { try { return WebDriverUtils.findElement(getDriver(), by); } catch (Throwable t) { checkForIncidentReport(by.toString(), t.getMessage()); jiraAwareFail(by.toString(), t.getMessage(), t); } return null; // required by compiler, never reached }
From source file:org.kuali.rice.testtools.selenium.JiraAwareAftBase.java
License:Educational Community License
protected WebElement findElement(By by, WebElement elementToFindOn) { try {/* ww w . j a v a 2 s . c o m*/ WebElement found = elementToFindOn.findElement(by); WebDriverUtils.highlightElement(getDriver(), found); return found; } catch (Throwable t) { checkForIncidentReport(by.toString(), t.getMessage()); jiraAwareFail(by.toString(), t.getMessage() + " " + this.getClass().toString(), t); } return null; // required by compiler, never reached }