/** * Instantiates a new no such element exception. * * @param description the description * @param cause the cause */ public NoSuchElementException(LogDescriptionBean description, org.openqa.selenium.NoSuchElementException cause) { super(null, cause); this.description = description; this.locator = parseLocator(cause.getMessage()); }
@Override public Object getTarget() { try { return dropProxyAndFindElement(by, searchContext); } catch (NoSuchElementException ex) { throw new NoSuchElementException((by instanceof ByIdOrName ? EMPTY_FIND_BY_WARNING : "") + ex.getMessage(), ex); } } });
@Override public Object getTarget() { try { return dropProxyAndFindElement(by, searchContext); } catch (NoSuchElementException ex) { throw new NoSuchElementException((by instanceof ByIdOrName ? EMPTY_FIND_BY_WARNING : "") + ex.getMessage(), ex); } } });
/** * Find the element list. */ public List<WebElement> findElements() { List<WebElement> elements = null; NoSuchElementException exception = null; try { elements = searchContext.findElements(by); } catch (NoSuchElementException e) { LOGGER.debug("Unable to find elements: " + e.getMessage()); } //TODO: incorporate find by AI??? // If no luck throw general NoSuchElementException if (elements == null) { throw exception != null ? exception : new NoSuchElementException("Unable to find elements by Selenium"); } // we can't enable cache for lists by default as we can't handle/catch list.get(index).action(). And for all dynamic lists // As result for all dynamic lists we have too often out of bound index exceptions return elements; }
@Override protected void isLoaded() throws Error { try { element = SmartAjaxElementLocator.super.findElement(); if (!isElementUsable(element)) { throw new NoSuchElementException("Element is not usable " + element.toString()); } } catch (NoSuchElementException e) { lastException = e; // Should use JUnit's AssertionError, but it may not be present throw new NoSuchElementError("Unable to locate the element: " + e.getMessage(), e); } }
@Override protected void isLoaded() throws Error { try { elements = SmartAjaxElementLocator.super.findElements(); if (elements.size() == 0) { /*return even if empty and don't wait for them to become available. *not sure that it is the correct approach for Ajax Element Locator that should wait for elements *however correcting it due to https://java.net/jira/browse/THUCYDIDES-187 */ return; } for (WebElement element : elements) { if (!isElementUsable(element)) { throw new NoSuchElementException("Element is not usable"); } } } catch (NoSuchElementException e) { lastException = e; // Should use JUnit's AssertionError, but it may not be present throw new NoSuchElementError("Unable to locate the element " + e.getMessage(), e); } }
public void verifyVideoInBrowser(Browser browser, String browserLabel, String chromeName, String videoElementId, boolean isActive) { if (isActive) { log.debug("Verifing element {} exists in browser of {}", videoElementId, chromeName); try { WebElement video = findElement(browserLabel, browser, videoElementId); if (video == null) { fail("Video element " + videoElementId + " was not found in browser of " + chromeName); } } catch (NoSuchElementException e) { fail(e.getMessage()); } log.debug("OK - element {} found in browser of {}", videoElementId, chromeName); } else { log.debug("Verifing element {} is missing from browser of {}", videoElementId, chromeName); try { waitWhileElement(browserLabel, browser, videoElementId); } catch (TimeoutException e) { fail(e.getMessage()); } log.debug("OK - element {} is missing from browser of {}", videoElementId, chromeName); } }
public WebElement findElement(String label, Browser browser, String id) { try { return new WebDriverWait(browser.getWebDriver(), testTimeout, POLLING_LATENCY) .until(ExpectedConditions.presenceOfElementLocated(By.id(id))); } catch (TimeoutException e) { log.warn("Timeout when waiting for element {} to exist in browser {}", id, label); int originalTimeout = 60; try { originalTimeout = browser.getTimeout(); log.debug("Original browser timeout (s): {}, set to 10", originalTimeout); browser.setTimeout(10); browser.changeTimeout(10); WebElement elem = browser.getWebDriver().findElement(By.id(id)); log.info("Additional findElement call was able to locate {} in browser {}", id, label); return elem; } catch (NoSuchElementException e1) { log.debug("Additional findElement call couldn't locate {} in browser {} ({})", id, label, e1.getMessage()); throw new NoSuchElementException("Element with id='" + id + "' not found after " + testTimeout + " seconds in browser " + label); } finally { browser.setTimeout(originalTimeout); browser.changeTimeout(originalTimeout); } } }
private boolean isElementVisible(WebElement element) { try { return element.isDisplayed(); } catch (NoSuchElementException e) { Log.info(e.getMessage()); return false; } }
/** * Method to check if WebElement is displayed on the page * * @return true if element is displayed, otherwise return false */ protected boolean isElementDisplayed(WebElement element) { try { return element.isDisplayed(); } catch (NoSuchElementException e) { Log.info(e.getMessage()); return false; } }
element = searchContext.findElements(by).get(0); LOGGER.debug("Unable to find element: " + e.getMessage());
String msg = e.getMessage(); int nlIndex = msg.indexOf('\n'); if (nlIndex > 0) {
@Test public void testFindNonExistingElement() { try { browser.findElement(ByJQuery.selector(":contains('non existing string')")); } catch (NoSuchElementException ex) { // this is desired state assertTrue("Error message of NoSuchElementException is wrong! ", ex.getMessage() .contains(EXPECTED_NO_SUCH_EL_EX_MSG)); return; } fail("There was not thrown NoSuchElementException when trying to locate non existed element!"); }
private void cmdJavaScriptOnClick(Properties p, String objectName, String objectType, WebDriverWait wait) throws Exception { // Si se ha configurado la propiedad de "Scroll and Click" entonces hace un scroll primero. if (scrollAndClick) { cmdScroll(p, objectName, objectType, wait, ""); } WebElement weAux; // Lo correcto seria poner: // weAux = buscarElemento(driver,this.getObject(p, objectName, objectType),p); // Pero entiendo que en este caso es lo mismo, con lo cual lo dejo como estaba y no hago el refactor // en estas instrucciones por si acaso hay un efecto no deseado entre la configuracion del timeOut del // wait y la de la tolerancia // weAux = (WebElement) wait.until(ExpectedConditions. // visibilityOfElementLocated(this.getObject(p, objectName, objectType))); try { weAux=buscarElemento(driver,this.getObject(p, objectName, objectType),p); JavascriptExecutor exec = (JavascriptExecutor) driver; exec.executeScript("arguments[0].on", weAux); }catch(NoSuchElementException e){ track.fail("Objeto No encontrado.\n" +e.getMessage()); } } /**
private void cmdJavaScriptClick(Properties p, String objectName, String objectType, WebDriverWait wait) throws Exception { // Si se ha configurado la propiedad de "Scroll and Click" entonces hace un scroll primero. if (scrollAndClick) { cmdScroll(p, objectName, objectType, wait, ""); } WebElement weAux; // Lo correcto seria poner: // weAux = buscarElemento(driver,this.getObject(p, objectName, objectType),p); // Pero entiendo que en este caso es lo mismo, con lo cual lo dejo como estaba y no hago el refactor // en estas instrucciones por si acaso hay un efecto no deseado entre la configuracion del timeOut del // wait y la de la tolerancia // weAux = (WebElement) wait.until(ExpectedConditions. // visibilityOfElementLocated(this.getObject(p, objectName, objectType))); try { weAux=buscarElemento(driver,this.getObject(p, objectName, objectType),p); JavascriptExecutor exec = (JavascriptExecutor) driver; exec.executeScript("arguments[0].click()", weAux); }catch(NoSuchElementException e){ track.fail("Objeto No encontrado.\n" +e.getMessage()); } }