org.openqa.selenium.NoSuchElementException Java Examples
The following examples show how to use
org.openqa.selenium.NoSuchElementException.
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: SelectAuthenticatorPage.java From keycloak with Apache License 2.0 | 6 votes |
@Override public boolean isCurrent() { // Check the title if (!DroneUtils.getCurrentDriver().getTitle().startsWith("Log in to ") && !DroneUtils.getCurrentDriver().getTitle().startsWith("Anmeldung bei ")) { return false; } // Check the authenticators-choice available try { driver.findElement(By.id("kc-select-credential-form")); } catch (NoSuchElementException nfe) { return false; } return true; }
Example #2
Source File: RoomClientBrowserTest.java From kurento-room with Apache License 2.0 | 6 votes |
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); } } }
Example #3
Source File: ExcludeInFrameTest.java From hifive-pitalium with Apache License 2.0 | 6 votes |
/** * BODYを撮影する際にiframe内外のs存在しない要素を除外する。 * * @ptl.expect エラーが発生せず、除外領域が保存されていないこと。 */ @Test public void captureBody_excludeNotExistElementInsideAndOutsideFrame() throws Exception { openIFramePage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().moveTarget(true).scrollTarget(false) .addExcludeByClassName("not-exists").addExcludeByClassName("not-exists").inFrameByClassName("content") .build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } assertionView.assertView(arg); // Check TargetResult result = loadTargetResults("s").get(0); assertThat(result.getExcludes(), is(empty())); }
Example #4
Source File: Select.java From webtester-core with Apache License 2.0 | 6 votes |
/** * Returns the first selected option's value. If nothing is selected * <code>null</code> is returned. * * @return the value of the first selected option. * @since 0.9.0 */ public String getFirstSelectedValue() { return executeAction(new PageObjectCallbackWithReturnValue<String>() { @Override public String execute(PageObject pageObject) { try { return getFirstSelectedOption().getAttribute("value"); } catch (NoSuchElementException e) { logger.warn(logMessage(NOTHING_SELECTED_VALUE)); return null; } } }); }
Example #5
Source File: NoSuchElementTest.java From hifive-pitalium with Apache License 2.0 | 6 votes |
/** * 存在しない要素を指定して撮影する。 * * @ptl.expect AssertionErrorが発生すること。 */ @Test public void noSuchElement() throws Exception { openBasicTextPage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTargetById("notExists").build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } else { expectedException.expect(AssertionError.class); expectedException.expectMessage("Invalid selector found"); } assertionView.assertView(arg); fail(); }
Example #6
Source File: HideMultiElementsTest.java From hifive-pitalium with Apache License 2.0 | 6 votes |
/** * 複数セレクタで複数の要素を指定して非表示にするが、そのうちのいずれかは存在しない要素である。 * * @ptl.expect エラーが発生せず、非表示に指定した要素が写っていないこと。 */ @Test public void multiTargets_notExist() throws Exception { openBasicColorPage(); ScreenshotArgument arg = ScreenshotArgument.builder("s").addNewTarget().addHiddenElementsById("not-exists") .addHiddenElementsById("colorColumn1").addHiddenElementsById("colorColumn2").build(); if (BrowserType.SAFARI.equals(capabilities.getBrowserName())) { expectedException.expect(NoSuchElementException.class); } assertionView.assertView(arg); // Check // 特定の色のピクセルが存在しないこと BufferedImage image = loadTargetResults("s").get(0).getImage().get(); int width = image.getWidth(); int height = image.getHeight(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Color actual = Color.valueOf(image.getRGB(x, y)); assertThat(actual, is(not(anyOf(equalTo(Color.GREEN), equalTo(Color.BLUE))))); } } }
Example #7
Source File: AugmenterTest.java From selenium with Apache License 2.0 | 6 votes |
@Test public void proxyShouldNotAppearInStackTraces() { // This will force the class to be enhanced final Capabilities caps = new ImmutableCapabilities("magic.numbers", true); DetonatingDriver driver = new DetonatingDriver(); driver.setCapabilities(caps); WebDriver returned = getAugmenter() .addDriverAugmentation( "magic.numbers", HasMagicNumbers.class, (c, exe) -> () -> 42) .augment(driver); assertThatExceptionOfType(NoSuchElementException.class) .isThrownBy(() -> returned.findElement(By.id("ignored"))); }
Example #8
Source File: Assertion.java From PatatiumWebUi with Apache License 2.0 | 5 votes |
/** * 验证页面是否出现某文本exceptStr * @param exceptStr 预期值 * @param Message 验证中文描述 * @author Administrator 郑树恒 */ public static void VerityTextPresent(String exceptStr,String Message) { String verityStr="【Assert验证】:"+"页面是否出现"+"【"+"预期值:"+exceptStr+"】"+"字符串"; Boolean flag=false; log.info(Message+":"+verityStr); try { exceptStr="//*[contains(text(),'"+exceptStr+"')]"; System.out.println(exceptStr); List<WebElement> webElements= driver.findElements(By.xpath(exceptStr)); if (webElements.size()>0) { flag=true; } else { flag=false; } } catch (NoSuchElementException e) { // TODO: handle exception flag=false; ElementAction.noSuchElementExceptions.add(e); e.printStackTrace(); } try { Assert.assertTrue(flag); AssertPassLog(); assertInfolList.add(Message+verityStr+":pass"); messageList.add(Message+":pass"); } catch (Error f) { // TODO: handle exception AssertFailedLog(); errors.add(f); errorIndex++; assertInfolList.add(Message+verityStr+":failed"); messageList.add(Message+":failed"); Assertion.snapshotInfo(); } }
Example #9
Source File: SigningInPage.java From keycloak with Apache License 2.0 | 5 votes |
public boolean isTitleVisible() { try { return getItemElement(TITLE).isDisplayed(); } catch (NoSuchElementException e) { return false; } }
Example #10
Source File: ExtendedWebElement.java From carina with Apache License 2.0 | 5 votes |
/** * Check that element with text present. * * @param text of element to check. * @param timeout - timeout. * @return element with text existence status. */ public boolean isElementWithTextPresent(final String text, long timeout) { final String decryptedText = cryptoTool.decryptByPattern(text, CRYPTO_PATTERN); ExpectedCondition<Boolean> textCondition; if (element != null) { ExpectedCondition<Boolean> tmpCondition = ExpectedConditions.and(ExpectedConditions.visibilityOf(element)); boolean tmpResult = waitUntil(tmpCondition, 0); if (!tmpResult && originalException != null && StaleElementReferenceException.class.equals(originalException.getClass())) { LOGGER.debug("StaleElementReferenceException detected in isElementWithTextPresent!"); try { refindElement(); textCondition = ExpectedConditions.textToBePresentInElement(element, decryptedText); } catch (NoSuchElementException e) { // search element based on By if exception was thrown textCondition = ExpectedConditions.textToBePresentInElementLocated(getBy(), decryptedText); } } textCondition = ExpectedConditions.textToBePresentInElement(element, decryptedText); } else { textCondition = ExpectedConditions.textToBePresentInElementLocated(getBy(), decryptedText); } return waitUntil(textCondition, timeout); //TODO: restore below code as only projects are migrated to "isElementWithContainTextPresent" // return waitUntil(ExpectedConditions.and(ExpectedConditions.presenceOfElementLocated(getBy()), // ExpectedConditions.textToBe(getBy(), decryptedText)), timeout); }
Example #11
Source File: SelectElementTest.java From selenium with Apache License 2.0 | 5 votes |
@Test public void shouldThrowExceptionOnSelectByReturnedValueIfOptionDoesNotExist() { WebElement selectElement = driver.findElement(By.name("select_empty_multiple")); Select select = new Select(selectElement); assertThatExceptionOfType(NoSuchElementException.class) .isThrownBy(() -> select.selectByValue("not there")); }
Example #12
Source File: Select.java From bobcat with Apache License 2.0 | 5 votes |
/** * Selects given options of select component. * * @param value String value of comma delimited field names which will be selected. */ @Override public void setValue(Object value) { selectField.click(); List<WebElement> options = selectField.findElements(By.cssSelector(SELECT_OPTIONS_CSS)); options.stream().filter(o -> value.toString().equals(o.getText())) .findFirst() .orElseThrow(() -> new NoSuchElementException( String.format("Option with text %s not found", value.toString()))).click(); }
Example #13
Source File: Sidebar.java From keycloak with Apache License 2.0 | 5 votes |
public void assertNavNotPresent(String id) { try { getNavElement(id).isDisplayed(); throw new AssertionError("Nav element " + id + " shouldn't be present"); } catch (NoSuchElementException e) { // ok } }
Example #14
Source File: FrameWebElementTest.java From hifive-pitalium with Apache License 2.0 | 5 votes |
/** * Frameにスイッチできないテスト */ @Test public void executeInFrame_not_inFrameElement() throws Exception { PtlWebElement iframe = (PtlWebElement) driver.findElementByClassName("content"); expectedException.expect(NoSuchElementException.class); iframe.executeInFrame(new Supplier<WebElement>() { @Override public WebElement get() { return driver.findElementByClassName("content-left"); } }); }
Example #15
Source File: SigningInPage.java From keycloak with Apache License 2.0 | 5 votes |
public boolean isPresent() { try { return getItemElement(ROW).isDisplayed(); } catch (NoSuchElementException e) { return false; } }
Example #16
Source File: SpecialtiesPage.java From javaee7-petclinic with GNU General Public License v2.0 | 5 votes |
public void assertDeletedContentNotFound() { boolean isDeleted = false; try { Assert.assertEquals(null,nameInTable); } catch (NoSuchElementException elementException) { isDeleted = true; } Assert.assertTrue(isDeleted); }
Example #17
Source File: InstructorCoursesPage.java From teammates with GNU General Public License v2.0 | 5 votes |
private int getArchivedCourseCount() { try { return archivedCoursesTable.findElements(By.cssSelector("tbody tr")).size(); } catch (NoSuchElementException e) { return 0; } }
Example #18
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 #19
Source File: AskForValueDialog.java From che with Eclipse Public License 2.0 | 5 votes |
public boolean isWidgetNewJavaClassIsOpened() { try { return newJavaClass.isDisplayed(); } catch (NoSuchElementException ex) { return false; } }
Example #20
Source File: CustomScriptManagePage.java From oxTrust with MIT License | 5 votes |
public void fluentWaitForTableCompute(int finalSize) { Wait<WebDriver> wait = new FluentWait<WebDriver>(webDriver).withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS).ignoring(NoSuchElementException.class); wait.until(new Function<WebDriver, Boolean>() { public Boolean apply(WebDriver driver) { String className = "allScriptFor".concat(currentTabText.split("\\s+")[0]); WebElement firstElement = driver.findElement(By.className(className)).findElements(By.tagName("tr")) .get(0); List<WebElement> scripts = new ArrayList<>(); scripts.add(firstElement); scripts.addAll(firstElement.findElements(By.xpath("following-sibling::tr"))); return scripts.size() == (finalSize + 1); } }); }
Example #21
Source File: JTableTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void gettableCellNonexistant() throws Throwable { driver = new JavaDriver(); WebElement errCell = driver.findElement(By.cssSelector("table::mnth-cell(20,20)")); try { errCell.getText(); throw new MissingException(NoSuchElementException.class); } catch (NoSuchElementException e) { } }
Example #22
Source File: JavaDriverTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void findElementThrowsNoSuchElementIfNotFound() throws Throwable { driver = new JavaDriver(); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame.setLocationRelativeTo(null); frame.setVisible(true); } }); try { driver.findElement(By.name("click-me-note-there")); throw new MissingException(NoSuchElementException.class); } catch (NoSuchElementException e) { } }
Example #23
Source File: JListXTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void listThrowsNSEWhenIndexOutOfBounds() throws Throwable { driver = new JavaDriver(); try { WebElement findElement = driver.findElement(By.cssSelector("#list-1::nth-item(31)")); findElement.click(); throw new MissingException(NoSuchElementException.class); } catch (NoSuchElementException e) { } }
Example #24
Source File: JListTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void indexOutOfBoundException() throws Throwable { driver = new JavaDriver(); try { WebElement findElement = driver.findElement(By.cssSelector("list::nth-item(6)")); findElement.click(); throw new MissingException(NoSuchElementException.class); } catch (NoSuchElementException e) { } }
Example #25
Source File: SigningInPage.java From keycloak with Apache License 2.0 | 5 votes |
public boolean isSetUpLinkVisible() { try { return getItemElement(SET_UP).isDisplayed(); } catch (NoSuchElementException e) { return false; } }
Example #26
Source File: Assertion.java From PatatiumWebUi with Apache License 2.0 | 5 votes |
/** * 验证页面是否出现某文本exceptStr * @param exceptStr 预期值 * @author Administrator 郑树恒 */ public static void VerityTextPresent(String exceptStr) { String verityStr="【Assert验证】:"+"页面是否出现"+"【"+"预期值:"+exceptStr+"】"+"字符串"; Boolean flag=false; log.info(verityStr); try { exceptStr="//*[contains(text(),'"+exceptStr+"')]"; log.info("定位信息:"+exceptStr); driver.findElements(By.xpath(exceptStr)); if (driver.findElements(By.xpath(exceptStr)).size()>0) { flag=true; } else { flag=false; } } catch (NoSuchElementException e) { // TODO: handle exception flag=false; ElementAction.noSuchElementExceptions.add(e); e.printStackTrace(); ///AssertFailedLog(); } try { Assert.assertTrue(flag); AssertPassLog(); assertInfolList.add(verityStr+":pass"); } catch (Error f) { // TODO: handle exception AssertFailedLog(); errors.add(f); errorIndex++; assertInfolList.add(verityStr+":failed"); Assertion.snapshotInfo(); //throw f; } }
Example #27
Source File: Assertion.java From PatatiumWebUi with Apache License 2.0 | 5 votes |
/** * 验证页面是否没有出现莫文本exceptStr * @param exceptStr 预期值 * @param Message 验证中文描述 * @author Administrator 郑树恒 */ public static void VerityNotTextPresent(String exceptStr,String Message) { String verityStr="【Assert验证】:"+"页面是否没有出现"+"【"+"预期值:"+exceptStr+"】"+"字符串"; Boolean flag=false; log.info(Message+":"+verityStr); try { exceptStr="//*[contains(.,'"+exceptStr+"')]"; driver.findElement(By.xpath(exceptStr)); flag=false; System.out.println(flag); } catch (NoSuchElementException e) { // TODO: handle exception flag=true; System.out.println(flag); } try { Assert.assertTrue(flag); AssertPassLog(); System.out.println(flag); assertInfolList.add(Message+verityStr+":pass"); messageList.add(Message+":pass"); } catch (Error f) { // TODO: handle exception AssertFailedLog(); errors.add(f); errorIndex++; assertInfolList.add(Message+verityStr+":failed"); messageList.add(Message+":failed"); System.out.println(flag); Assertion.snapshotInfo(); } }
Example #28
Source File: DomSelectorTest.java From hifive-pitalium with Apache License 2.0 | 5 votes |
/** * body -> #main -> ??? */ @Test public void findElement_element_nested_notFound() throws Exception { expectedException.expect(NoSuchElementException.class); DomSelector selector = new DomSelector(SelectorType.CLASS_NAME, "none", new DomSelector(SelectorType.ID, "main")); selector.findElement(defaultContentElement); }
Example #29
Source File: GraphHandler.java From product-iots with Apache License 2.0 | 5 votes |
/** * Check the graph path is visible or not. * * @param graph : web element of the graph * @return : True if the path is visible. False otherwise */ public boolean isPathAvailable(WebElement graph) { try { WebElement graphContainer = getGraph(graph, uiElementMapper.getElement("iot.stat.graph.class.name")); return graphContainer != null && graphContainer.findElement(By.tagName("path")).isDisplayed(); } catch (NoSuchElementException e) { log.error(String.format("No element found. \n %s", e.getMessage())); return false; } }
Example #30
Source File: HandleResourceRunSteps.java From jwala with Apache License 2.0 | 5 votes |
/** * Insert text in the resource template/metadata text box * * @param inputStr the string that is to be inserted in the resource text box * @param atStr the String whose location is where the inputStr parameter will be inserted at */ @When("^I enter value \"(.*)\" in the edit box at text \"(.*)\"$") public void insertStrInTheResourceEditor(final String inputStr, final String atStr) { try { jwalaUi.click(By.xpath("(//pre[contains(@class, 'CodeMirror-line')]//span[text()='" + atStr.trim() + "'])[1]")); } catch (final NoSuchElementException e) { jwalaUi.click(By.xpath("(//pre[contains(@class, 'CodeMirror-line')]//span[contains(text(), '" + atStr.trim() + "')])[1]")); } jwalaUi.sendKeysViaActions(inputStr); }