org.openqa.selenium.InvalidElementStateException Java Examples
The following examples show how to use
org.openqa.selenium.InvalidElementStateException.
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: ComboBox.java From aquality-selenium-java with Apache License 2.0 | 6 votes |
private void selectOptionThatContains(Function<WebElement, String> getValueFunc, BiConsumer<Select, String> selectFunc, String value){ doWithRetry(() -> { Select select = new Select(getElement()); List<WebElement> elements = select.getOptions(); boolean isSelected = false; for (WebElement el: elements) { String currentValue = getValueFunc.apply(el); getLogger().debug(currentValue); if(currentValue.toLowerCase().contains(value.toLowerCase())){ selectFunc.accept(select, currentValue); isSelected = true; } } if (!isSelected){ throw new InvalidElementStateException(String.format(getLocalizationManager().getLocalizedMessage( "loc.combobox.impossible.to.select.contain.value.or.text"), value, getName())); } }); }
Example #2
Source File: FollowLinkTest.java From demo-java with MIT License | 6 votes |
/** * Runs a simple test verifying link can be followed. * * @throws InvalidElementStateException */ @Test(dataProvider = "hardCodedBrowsers") public void verifyLinkTest(String platformName, String deviceName, String platformVersion, String appiumVersion, String deviceOrientation, Method method) throws MalformedURLException, InvalidElementStateException, UnexpectedException { //create webdriver session this.createDriver(platformName, deviceName, platformVersion, appiumVersion, deviceOrientation, method.getName()); WebDriver driver = this.getAndroidDriver(); GuineaPigPage page = new GuineaPigPage(driver); page.followLink(); Assert.assertFalse(page.isOnPage()); }
Example #3
Source File: TextInputTest.java From demo-java with MIT License | 6 votes |
/** * Runs a simple test verifying if the comment input is functional. * @throws InvalidElementStateException */ @org.testng.annotations.Test(dataProvider = "hardCodedBrowsers") public void verifyCommentInputTest(String platformName, String deviceName, String platformVersion, String appiumVersion, String deviceOrientation, Method method) throws MalformedURLException, InvalidElementStateException, UnexpectedException { this.createDriver(platformName, deviceName, platformVersion, appiumVersion, deviceOrientation, method.getName()); WebDriver driver = this.getAndroidDriver(); String commentInputText = UUID.randomUUID().toString(); GuineaPigPage page = new GuineaPigPage(driver); page.submitComment(commentInputText); Assert.assertTrue(page.getSubmittedCommentText().contains(commentInputText)); }
Example #4
Source File: FollowLinkTest.java From demo-java with MIT License | 6 votes |
/** * Runs a simple test verifying link can be followed. * * @throws InvalidElementStateException */ @Test(dataProvider = "hardCodedBrowsers") public void verifyLinkTest(String platformName, String deviceName, String platformVersion, String appiumVersion, String deviceOrientation, Method method) throws MalformedURLException, InvalidElementStateException, UnexpectedException { //create webdriver session this.createDriver(platformName, deviceName, platformVersion, appiumVersion, deviceOrientation, method.getName()); WebDriver driver = this.getiosDriver(); GuineaPigPage page = new GuineaPigPage(driver); page.followLink(); Assert.assertFalse(page.isOnPage()); }
Example #5
Source File: TextInputTest.java From demo-java with MIT License | 6 votes |
/** * Runs a simple test verifying if the comment input is functional. * @throws InvalidElementStateException */ @org.testng.annotations.Test(dataProvider = "hardCodedBrowsers") public void verifyCommentInputTest(String platformName, String deviceName, String platformVersion, String appiumVersion, String deviceOrientation, Method method) throws MalformedURLException, InvalidElementStateException, UnexpectedException { this.createDriver(platformName, deviceName, platformVersion, appiumVersion, deviceOrientation, method.getName()); WebDriver driver = this.getiosDriver(); String commentInputText = UUID.randomUUID().toString(); GuineaPigPage page = new GuineaPigPage(driver); page.submitComment(commentInputText); Assert.assertTrue(page.getSubmittedCommentText().contains(commentInputText)); }
Example #6
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 #7
Source File: ElementActionRetrierTests.java From aquality-selenium-java with Apache License 2.0 | 5 votes |
@DataProvider private Object[][] handledExceptions() { return new Object[][] { { new StaleElementReferenceException("") }, { new InvalidElementStateException("")} }; }
Example #8
Source File: HtmlNumberInputTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void typeWhileDisabled() throws Exception { final String html = "<html><body><input type='number' id='p' disabled='disabled'/></body></html>"; final WebDriver driver = loadPage2(html); final WebElement p = driver.findElement(By.id("p")); try { p.sendKeys("abc"); fail(); } catch (final InvalidElementStateException e) { // as expected } assertEquals("", p.getAttribute("value")); }
Example #9
Source File: HtmlTextInputTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void typeWhileDisabled() throws Exception { final String html = "<html><body><input type='text' id='p' disabled='disabled'/></body></html>"; final WebDriver driver = loadPage2(html); final WebElement p = driver.findElement(By.id("p")); try { p.sendKeys("abc"); fail(); } catch (final InvalidElementStateException e) { // as expected } assertEquals("", p.getAttribute("value")); }
Example #10
Source File: HtmlPasswordInputTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test public void typeWhileDisabled() throws Exception { final String html = "<html><body><input type='password' id='p' disabled='disabled'/></body></html>"; final WebDriver driver = loadPage2(html); final WebElement p = driver.findElement(By.id("p")); try { p.sendKeys("abc"); fail(); } catch (final InvalidElementStateException e) { // as expected } assertEquals("", p.getAttribute("value")); }
Example #11
Source File: DomElementTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception on test failure */ @Test(expected = InvalidElementStateException.class) public void sendKeysToDisabled() throws Exception { final String html = "<html>\n" + "<body>\n" + " <input id='id1' disabled>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); driver.findElement(By.id("id1")).sendKeys("Hello"); }
Example #12
Source File: AppPage.java From teammates with GNU General Public License v2.0 | 5 votes |
/** * Simulates the clearing and sending of keys to an element. * * <p><b>Note:</b> This method is not the same as using {@link WebElement#clear} followed by {@link WebElement#sendKeys}. * It avoids double firing of the {@code change} event which may occur when {@link WebElement#clear} is followed by * {@link WebElement#sendKeys}. * * @see AppPage#clearWithoutEvents(WebElement) */ private void clearAndSendKeys(WebElement element, CharSequence... keysToSend) { Map<String, Object> result = clearWithoutEvents(element); @SuppressWarnings("unchecked") Map<String, String> errors = (Map<String, String>) result.get("errors"); if (errors != null) { throw new InvalidElementStateException(errors.get("detail")); } element.sendKeys(keysToSend); }
Example #13
Source File: AppPage.java From teammates with GNU General Public License v2.0 | 5 votes |
/** * Simulates the clearing and sending of keys to an element. * * <p><b>Note:</b> This method is not the same as using {@link WebElement#clear} followed by {@link WebElement#sendKeys}. * It avoids double firing of the {@code change} event which may occur when {@link WebElement#clear} is followed by * {@link WebElement#sendKeys}. * * @see AppPage#clearWithoutEvents(WebElement) */ private void clearAndSendKeys(WebElement element, CharSequence... keysToSend) { Map<String, Object> result = clearWithoutEvents(element); @SuppressWarnings("unchecked") Map<String, String> errors = (Map<String, String>) result.get("errors"); if (errors != null) { throw new InvalidElementStateException(errors.get("detail")); } element.sendKeys(keysToSend); }
Example #14
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 #15
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); }); } }