org.openqa.selenium.ElementNotVisibleException Java Examples
The following examples show how to use
org.openqa.selenium.ElementNotVisibleException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CalculateOffsetPosition.java From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License | 6 votes |
private void calculateOffset() throws ElementNotVisibleException { int parentHeight = parentElement.getSize().getHeight(); int parentWidth = parentElement.getSize().getWidth(); int childHeight = childElement.getSize().getHeight(); int childWidth = childElement.getSize().getWidth(); if (childHeight >= parentHeight && childWidth >= parentWidth) { throw new ElementNotVisibleException("The child element is totally covering the parent element"); } if (cursorPosition.equals(TOP_LEFT)) { xOffset = 1; yOffset = 1; } if (cursorPosition.equals(CENTER)) { if (childWidth < parentWidth) { xOffset = (childWidth / 2) + 1; } if (childHeight < parentHeight) { yOffset = (childHeight / 2) + 1; } } }
Example #2
Source File: RealHtmlButton.java From ats-framework with Apache License 2.0 | 6 votes |
private void doClick() { try { new RealHtmlElementState(this).waitToBecomeExisting(); WebElement element = RealHtmlElementLocator.findElement(this); try { element.click(); } catch (ElementNotVisibleException enve) { if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) { throw enve; } ((JavascriptExecutor) webDriver).executeScript("arguments[0].click()", element); } } catch (Exception e) { ((AbstractRealBrowserDriver) super.getUiDriver()).clearExpectedPopups(); throw new SeleniumOperationException(this, "click", e); } UiEngineUtilities.sleep(); ((AbstractRealBrowserDriver) super.getUiDriver()).handleExpectedPopups(); }
Example #3
Source File: NativeAppDriver.java From edx-app-android with Apache License 2.0 | 6 votes |
/** * Overridden webDriver find Elements with proper wait. */ @Override public List<WebElement> findElements(By locator) { try { (new WebDriverWait(appiumDriver, maxWaitTime)) .until(ExpectedConditions .presenceOfAllElementsLocatedBy(locator)); } catch (ElementNotVisibleException e) { Reporter.log("Element not found: " + locator.toString()); captureScreenshot(); throw e; } return appiumDriver.findElements(locator); }
Example #4
Source File: ErrorHandlerTest.java From selenium with Apache License 2.0 | 6 votes |
@Test public void testThrowsCorrectExceptionTypes() { assertThrowsCorrectExceptionType(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class); assertThrowsCorrectExceptionType(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class); assertThrowsCorrectExceptionType(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class); assertThrowsCorrectExceptionType( ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class); assertThrowsCorrectExceptionType( ErrorCodes.METHOD_NOT_ALLOWED, UnsupportedCommandException.class); assertThrowsCorrectExceptionType( ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class); assertThrowsCorrectExceptionType( ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class); assertThrowsCorrectExceptionType( ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class); assertThrowsCorrectExceptionType( ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class); assertThrowsCorrectExceptionType(ErrorCodes.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesException.class); }
Example #5
Source File: PageBase.java From SeleniumCucumber with GNU General Public License v3.0 | 5 votes |
public void waitForElement(WebElement element,int timeOutInSeconds) { WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.ignoring(NoSuchElementException.class); wait.ignoring(ElementNotVisibleException.class); wait.ignoring(StaleElementReferenceException.class); wait.ignoring(ElementNotFoundException.class); wait.pollingEvery(250,TimeUnit.MILLISECONDS); wait.until(elementLocated(element)); }
Example #6
Source File: WaitHelper.java From SeleniumCucumber with GNU General Public License v3.0 | 5 votes |
private WebDriverWait getWait(int timeOutInSeconds,int pollingEveryInMiliSec) { oLog.debug(""); WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.pollingEvery(pollingEveryInMiliSec, TimeUnit.MILLISECONDS); wait.ignoring(NoSuchElementException.class); wait.ignoring(ElementNotVisibleException.class); wait.ignoring(StaleElementReferenceException.class); wait.ignoring(NoSuchFrameException.class); return wait; }
Example #7
Source File: RoomClientBrowserTest.java From kurento-room with Apache License 2.0 | 5 votes |
public void exitFromRoom(int pageIndex, String userName) { Browser userBrowser = getPage(getBrowserKey(pageIndex)).getBrowser(); try { Actions actions = new Actions(userBrowser.getWebDriver()); actions.click(findElement(userName, userBrowser, "buttonLeaveRoom")).perform(); log.debug("'buttonLeaveRoom' clicked on in {}", userName); } catch (ElementNotVisibleException e) { log.warn("Button 'buttonLeaveRoom' is not visible. Session can't be closed"); } }
Example #8
Source File: RoomClientBrowserTest.java From kurento-room with Apache License 2.0 | 5 votes |
public void unsubscribe(int pageIndex, int unsubscribeFromIndex) { String clickableVideoTagId = getBrowserVideoStreamName(unsubscribeFromIndex); selectVideoTag(pageIndex, clickableVideoTagId); WebDriver userWebDriver = getPage(getBrowserKey(pageIndex)).getBrowser().getWebDriver(); try { userWebDriver.findElement(By.id("buttonDisconnect")).click(); } catch (ElementNotVisibleException e) { String msg = "Button 'buttonDisconnect' is not visible. Can't unsubscribe from media."; log.warn(msg); fail(msg); } }
Example #9
Source File: RoomClientBrowserTest.java From kurento-room with Apache License 2.0 | 5 votes |
public void selectVideoTag(int pageIndex, String targetVideoTagId) { WebDriver userWebDriver = getPage(getBrowserKey(pageIndex)).getBrowser().getWebDriver(); try { WebElement element = userWebDriver.findElement(By.id(targetVideoTagId)); Actions actions = new Actions(userWebDriver); actions.moveToElement(element).click().perform(); } catch (ElementNotVisibleException e) { String msg = "Video tag '" + targetVideoTagId + "' is not visible, thus not selectable."; log.warn(msg); fail(msg); } }
Example #10
Source File: RoomClientBrowserTest.java From kurento-room with Apache License 2.0 | 5 votes |
protected void unpublish(int pageIndex) { WebDriver userWebDriver = getPage(getBrowserKey(pageIndex)).getBrowser().getWebDriver(); try { userWebDriver.findElement(By.id("buttonDisconnect")).click(); } catch (ElementNotVisibleException e) { log.warn("Button 'buttonDisconnect' is not visible. Can't unpublish media."); } }
Example #11
Source File: SeleniumCheck.java From phoenix.webui.framework with Apache License 2.0 | 4 votes |
@Override public void checkByValue(Element element, String value) { WebElement parentWebEle = searchStrategyUtils.findStrategy(WebElement.class, element).search(element); if(parentWebEle == null) { logger.error(String.format("can not found element byText [%s].", value)); return; } List<Locator> locatorList = element.getLocatorList(); List<Locator> tmpList = new ArrayList<Locator>(locatorList); ElementSearchStrategy<WebElement> strategy = context.getBean("zoneSearchStrategy", ElementSearchStrategy.class); SeleniumValueLocator valueLocator = context.getBean(SeleniumValueLocator.class); valueLocator.setHostType("byTagName"); valueLocator.setHostValue("input"); locatorList.clear(); locatorList.add(valueLocator); valueLocator.setValue(value); WebElement itemWebEle = null; try { if(strategy instanceof ParentElement) { ((ParentElement) strategy).setParent(parentWebEle); } itemWebEle = strategy.search(element); if(itemWebEle != null) { if(!itemWebEle.isSelected()) { itemWebEle.click(); } } } catch(ElementNotVisibleException e) { e.printStackTrace(); logger.error(String.format("Element [%s] click error, parent [%s], text [%s].", itemWebEle, element, value)); } finally { //清空缓存 locatorList.clear(); locatorList.addAll(tmpList); if(strategy instanceof ParentElement) { ((ParentElement) strategy).setParent(null); } } }
Example #12
Source File: HtmlFileBrowse.java From ats-framework with Apache License 2.0 | 4 votes |
/** * * @param webDriver {@link WebDriver} instance * @param value the file input value to set */ protected void setFileInputValue( WebDriver webDriver, String value ) { String locator = this.getElementProperties() .getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR); String css = this.getElementProperty("_css"); WebElement element = null; if (!StringUtils.isNullOrEmpty(css)) { element = webDriver.findElement(By.cssSelector(css)); } else { element = webDriver.findElement(By.xpath(locator)); } try { element.sendKeys(value); } catch (ElementNotVisibleException enve) { if (!UiEngineConfigurator.getInstance().isWorkWithInvisibleElements()) { throw enve; } // try to make the element visible overriding some CSS properties // but keep in mind that it can be still invisible using another CSS and/or JavaScript techniques String styleAttrValue = element.getAttribute("style"); JavascriptExecutor jsExec = (JavascriptExecutor) webDriver; try { jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "display:'block'; visibility:'visible'; top:'auto'; left:'auto'; z-index:999;" + "height:'auto'; width:'auto';"); element.sendKeys(value); } finally { jsExec.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, styleAttrValue); } } catch (InvalidElementStateException e) { throw new SeleniumOperationException(e.getMessage(), e); } }
Example #13
Source File: ErrorHandlerTest.java From selenium with Apache License 2.0 | 4 votes |
@Test public void testStatusCodesRaisedBackToStatusMatches() { Map<Integer, Class<?>> exceptions = new HashMap<>(); exceptions.put(ErrorCodes.NO_SUCH_SESSION, NoSuchSessionException.class); exceptions.put(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class); exceptions.put(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class); exceptions.put(ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class); exceptions.put(ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class); exceptions.put(ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class); exceptions.put(ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class); exceptions.put(ErrorCodes.UNHANDLED_ERROR, WebDriverException.class); exceptions.put(ErrorCodes.ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class); exceptions.put(ErrorCodes.JAVASCRIPT_ERROR, JavascriptException.class); exceptions.put(ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class); exceptions.put(ErrorCodes.TIMEOUT, TimeoutException.class); exceptions.put(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class); exceptions.put(ErrorCodes.INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class); exceptions.put(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class); exceptions.put(ErrorCodes.UNEXPECTED_ALERT_PRESENT, UnhandledAlertException.class); exceptions.put(ErrorCodes.NO_ALERT_PRESENT, NoAlertPresentException.class); exceptions.put(ErrorCodes.ASYNC_SCRIPT_TIMEOUT, ScriptTimeoutException.class); exceptions.put(ErrorCodes.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesException.class); exceptions.put(ErrorCodes.IME_NOT_AVAILABLE, ImeNotAvailableException.class); exceptions.put(ErrorCodes.IME_ENGINE_ACTIVATION_FAILED, ImeActivationFailedException.class); exceptions.put(ErrorCodes.INVALID_SELECTOR_ERROR, InvalidSelectorException.class); exceptions.put(ErrorCodes.SESSION_NOT_CREATED, SessionNotCreatedException.class); exceptions.put(ErrorCodes.MOVE_TARGET_OUT_OF_BOUNDS, MoveTargetOutOfBoundsException.class); exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR, InvalidSelectorException.class); exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR_RETURN_TYPER, InvalidSelectorException.class); for (Map.Entry<Integer, Class<?>> exception : exceptions.entrySet()) { assertThatExceptionOfType(WebDriverException.class) .isThrownBy(() -> handler.throwIfResponseFailed(createResponse(exception.getKey()), 123)) .satisfies(e -> { assertThat(e.getClass().getSimpleName()).isEqualTo(exception.getValue().getSimpleName()); // all of the special invalid selector exceptions are just mapped to the generic invalid selector int expected = e instanceof InvalidSelectorException ? ErrorCodes.INVALID_SELECTOR_ERROR : exception.getKey(); assertThat(new ErrorCodes().toStatusCode(e)).isEqualTo(expected); }); } }