类org.openqa.selenium.ElementNotVisibleException源码实例Demo

下面列出了怎么用org.openqa.selenium.ElementNotVisibleException的API类实例代码及写法,或者点击链接到github查看源代码。

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;
        }
    }
}
 
源代码2 项目: ats-framework   文件: RealHtmlButton.java
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();
    }
 
源代码3 项目: edx-app-android   文件: NativeAppDriver.java
/**
 * 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);

}
 
源代码4 项目: selenium   文件: ErrorHandlerTest.java
@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);
}
 
源代码5 项目: SeleniumCucumber   文件: PageBase.java
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));
}
 
源代码6 项目: SeleniumCucumber   文件: WaitHelper.java
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;
}
 
源代码7 项目: kurento-room   文件: RoomClientBrowserTest.java
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");
  }
}
 
源代码8 项目: kurento-room   文件: RoomClientBrowserTest.java
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);
  }
}
 
源代码9 项目: kurento-room   文件: RoomClientBrowserTest.java
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);
  }
}
 
源代码10 项目: kurento-room   文件: RoomClientBrowserTest.java
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.");
  }
}
 
源代码11 项目: phoenix.webui.framework   文件: SeleniumCheck.java
@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);
		}
	}
}
 
源代码12 项目: ats-framework   文件: HtmlFileBrowse.java
/**
*
* @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);
    }
}
 
源代码13 项目: selenium   文件: ErrorHandlerTest.java
@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);
        });
  }
}
 
 类所在包
 类方法
 同包方法