org.openqa.selenium.NotFoundException Java Examples

The following examples show how to use org.openqa.selenium.NotFoundException. 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: MobileContextUtils.java    From carina with Apache License 2.0 6 votes vote down vote up
public void switchMobileContext(View context) {
    AppiumDriver<?> driver = (AppiumDriver<?>) getDriverSafe();
    DriverHelper help = new DriverHelper();
    Set<String> contextHandles = help.performIgnoreException(driver::getContextHandles);
    String desiredContext = "";
    boolean isContextPresent = false;
    LOGGER.info("Existing contexts: ");
    for (String cont : contextHandles) {
        if (cont.contains(context.getView())) {
            desiredContext = cont;
            isContextPresent = true;
        }
        LOGGER.info(cont);
    }
    if (!isContextPresent) {
        throw new NotFoundException("Desired context is not present");
    }
    LOGGER.info("Switching to context : " + context.getView());
    driver.context(desiredContext);
}
 
Example #2
Source File: MobileContextUtils.java    From carina-demo with Apache License 2.0 6 votes vote down vote up
public void switchMobileContext(View context) {
    AppiumDriver<?> driver = (AppiumDriver<?>) getDriverSafe();
    DriverHelper help = new DriverHelper();
    Set<String> contextHandles = help.performIgnoreException(driver::getContextHandles);
    String desiredContext = "";
    boolean isContextPresent = false;
    LOGGER.info("Existing contexts: ");
    for (String cont : contextHandles) {
        if (cont.contains(context.getView())) {
            desiredContext = cont;
            isContextPresent = true;
        }
        LOGGER.info(cont);
    }
    if (!isContextPresent) {
        throw new NotFoundException("Desired context is not present");
    }
    LOGGER.info("Switching to context : " + context.getView());
    driver.context(desiredContext);
}
 
Example #3
Source File: ViewWebDriverTargetTest.java    From darcy-webdriver with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldCacheWindowHandleOnceFound() {
    ControllableView view = new ControllableView();
    view.setIsLoaded(true);

    WebDriverTarget target = WebDriverTargets.withViewLoaded(view, context);

    WebDriver firstSwitch = target.switchTo(locator);

    view.setIsLoaded(false);

    try {
        WebDriver secondSwitch = target.switchTo(locator);

        assertEquals(firstSwitch, secondSwitch);
    } catch (NotFoundException e) {
        fail("Second switch tried to find window again:\n" + e);
    }
}
 
Example #4
Source File: EnglishCountiesPage.java    From frameworkium-examples with Apache License 2.0 5 votes vote down vote up
public int populationOf(String countyName) {
    Predicate<WebElement> headerLookUp = e -> e.getText().trim().equals("County");
    Predicate<WebElement> lookUpCellMatcher = e -> e.getText().trim().equals(countyName);
    Predicate<WebElement> targetColHeaderLookup = e -> e.getText().trim().startsWith("Population");
    String population = listTable
            .getCellsByLookup(headerLookUp, lookUpCellMatcher, targetColHeaderLookup)
            .findFirst()
            .orElseThrow(NotFoundException::new)
            .getText()
            .replaceAll(",", "");
    return Integer.parseInt(population);
}
 
Example #5
Source File: WebDriverWait.java    From selenium with Apache License 2.0 5 votes vote down vote up
/**
 * @param driver the WebDriver instance to pass to the expected conditions
 * @param clock used when measuring the timeout
 * @param sleeper used to make the current thread go to sleep
 * @param timeout the timeout when an expectation is called
 * @param sleep the timeout used whilst sleeping
 */
public WebDriverWait(
    WebDriver driver, Duration timeout, Duration sleep, Clock clock, Sleeper sleeper) {
  super(driver, clock, sleeper);
  withTimeout(timeout);
  pollingEvery(sleep);
  ignoring(NotFoundException.class);
  this.driver = driver;
}
 
Example #6
Source File: ForwardingTargetedWebDriver.java    From darcy-webdriver with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isPresent() {
    try {
        driver().getTitle();
        return true;
    } catch (NotFoundException e) {
        return false;
    }
}
 
Example #7
Source File: WebDriverElement.java    From darcy-webdriver with GNU General Public License v3.0 5 votes vote down vote up
private WebElement webElement() {
    if (cached == null) {
        try {
            cached = getWrappedElement();
        } catch (NotFoundException e) {
            throw new FindableNotPresentException(this, e);
        }
    }

    return cached;
}
 
Example #8
Source File: WebDriverElement.java    From darcy-webdriver with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isPresent() {
    try {
        getWrappedElement();
        return true;
    } catch (NotFoundException e) {
        return false;
    }
}
 
Example #9
Source File: EnglishCountiesPage.java    From frameworkium-core with Apache License 2.0 5 votes vote down vote up
public int populationOf(String countyName) {
    Predicate<WebElement> headerLookUp = e -> e.getText().trim().equals("County");
    Predicate<WebElement> lookUpCellMatcher = e -> e.getText().trim().equals(countyName);
    Predicate<WebElement> targetColHeaderLookup = e -> e.getText().trim().startsWith("Population");
    String population = listTable
            .getCellsByLookup(headerLookUp, lookUpCellMatcher, targetColHeaderLookup)
            .findFirst()
            .orElseThrow(NotFoundException::new)
            .getText()
            .replaceAll(",", "");
    return Integer.parseInt(population);
}
 
Example #10
Source File: CaptureExecutionAPITest.java    From frameworkium-core with Apache License 2.0 5 votes vote down vote up
@Test
public void new_execution_has_status_new_and_last_updated_equals_created() {
    String id = new ExecutionService()
            .createExecution(createExMessage)
            .executionID;
    ExecutionResponse execution = new ExecutionService()
            .getExecutions(1, 20)
            .results.stream()
            .filter(ex -> id.equals(ex.executionID))
            .findFirst().orElseThrow(NotFoundException::new);
    assertThat(execution.currentStatus).isEqualTo("new");
    assertThat(execution.lastUpdated).isEqualTo(execution.created);
}
 
Example #11
Source File: Edition090_Image_Element_Optimization.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private WebElement findImageWithOptimizationNotes(String imageName) throws Exception {
    String imageData = getReferenceImageB64(imageName);
    WebElement el = null;
    double max = 1.0;
    double min = 0.0;
    double haltSearchSpread = 0.05;
    double check = 0;
    NotFoundException notFound = null;

    while (Math.abs(max - min) > haltSearchSpread) {
        check = (max + min) / 2;
        driver.setSetting(Setting.IMAGE_MATCH_THRESHOLD, check);
        try {
            el = driver.findElement(MobileBy.image(imageData));
            min = check;
        } catch (NotFoundException err) {
            max = check;
            notFound = err;
        }
    }

    if (el != null) {
        System.out.println("Image '" + imageName + "' was found at the highest threshold of: " + check);
        return el;
    }

    System.out.println("Image '" + imageName + "' could not be found even at a threshold as low as: " + check);
    throw notFound;
}
 
Example #12
Source File: HighestMountainPage.java    From frameworkium-examples with Apache License 2.0 5 votes vote down vote up
private String getText(String mountainName, int index) {
    return listTable.getRows()
            .map(row -> row.limit(index + 2).collect(toList()))
            .filter(row -> row.get(1).getText().contains(mountainName))
            .findFirst()
            .orElseThrow(NotFoundException::new)
            .get(index)
            .getText();
}
 
Example #13
Source File: CaptureExecutionAPITest.java    From frameworkium-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void new_execution_has_status_new_and_last_updated_equals_created() {
    String id = new ExecutionService()
            .createExecution(createExMessage)
            .executionID;
    var response = new ExecutionService()
            .getExecutions(1, 20)
            .results.stream()
            .filter(ex -> id.equals(ex.executionID))
            .findFirst().orElseThrow(NotFoundException::new);
    assertThat(response.currentStatus).isEqualTo("new");
    assertThat(response.lastUpdated).isEqualTo(response.created);
}
 
Example #14
Source File: Table.java    From seleniumtestsframework with Apache License 2.0 5 votes vote down vote up
public void findElement() {
    super.findElement();
    try {
        rows = element.findElements(By.tagName("tr"));
    } catch (NotFoundException e) { }

}
 
Example #15
Source File: WaitUtil.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public <T> Function<WebDriver, Integer> orVisible(Function<WebDriver, WebElement> trueCase, Function<WebDriver, WebElement> falseCase) {
    return driver -> {
        try {
            if(trueCase.apply(driver).isDisplayed()) {
                return 1;
            }
        } catch (NotFoundException e) {
            if(falseCase.apply(driver).isDisplayed()) {
                return 2;
            }
        }

        throw new NotFoundException();
    };
}
 
Example #16
Source File: ClassicJobApi.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public <T> T until(Function<JenkinsServer, T> function, long timeoutInMS) {
    return new FluentWait<JenkinsServer>(jenkins)
        .pollingEvery(500, TimeUnit.MILLISECONDS)
        .withTimeout(timeoutInMS, TimeUnit.MILLISECONDS)
        .ignoring(NotFoundException.class)
        .until((JenkinsServer server) -> function.apply(server));
}
 
Example #17
Source File: HiddenHtmlElementState.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isElementPresent() {

    try {

        if ( (element.getUiDriver() instanceof HiddenBrowserDriver)
             && (element instanceof UiAlert || element instanceof UiPrompt || element instanceof UiConfirm)) {
            return false;
        }

        if (element instanceof UiAlert || element instanceof UiConfirm) {
            Alert dialog = webDriver.switchTo().alert();
            return dialog != null;
        } else if (element instanceof UiPrompt) {

            Alert prompt = webDriver.switchTo().alert();
            return prompt.getText() != null && !prompt.getText().equals("false");
            // return seleniumBrowser.isPromptPresent(); // Not implemented yet
        }

        HiddenHtmlElementLocator.findElement(this.element, null, false);
        return true;
    } catch (NotFoundException nfe) {
        return false;
    } catch (ElementNotFoundException enfe) {
        return false;
    }

}
 
Example #18
Source File: WebHome.java    From xframium-java with GNU General Public License v3.0 4 votes vote down vote up
/**
 * xFramium can be used with the standard Selenium and Appium interfaces.  Use the TestContainer and TestPackge as descriped below as well
 * as the hook into the internal reporting system
 * @param testContainer
 * @throws Exception
 */

@Test( dataProvider = "deviceManager" )
public void testNativeSeleniumAppium( TestContainer testContainer ) throws Exception
{
    //
    // Get access to the test and device
    //
    TestPackage testPackage = testPackageContainer.get();      
    TestName testName = testPackage.getTestName();
    
    //
    // Enable some basic reporting
    //
    DeviceWebDriver webDriver = testPackage.getConnectedDevice().getWebDriver();
    webDriver.setReportingElement( true );
    
    
    //
    // Optionally start a step container to allowing for reporting structure
    //
    startStep( testName, "Step One", "Testing the Toggle Button" );
    String beforeClick = webDriver.findElement( By.id( "singleModel" ) ).getText();
    webDriver.findElement( By.xpath( "//button[text()='Toggle Value']" ) ).click();
    String afterClick = webDriver.findElement( By.id( "singleModel" ) ).getText();
    
    Assert.assertFalse( (Boolean) executeStep( "COMPARE2", "Step One", CompareType.STRING.name(), new String[] { "Value One==" + beforeClick, "Value Two==" + afterClick }, webDriver ).get( "RESULT" ) );
    dumpState( webDriver );
    
    
    
    stopStep( testName, StepStatus.SUCCESS, null );
    
    startStep( testName, "Step Two", "Testing Attributes" );
    String typeAttribute = webDriver.findElement( By.xpath( "//button[text()='Toggle Value']" ) ).getAttribute( "type" );
    Assert.assertTrue( (Boolean) executeStep( "COMPARE2", "Step One", CompareType.STRING.name(), new String[] { "Value One==" + typeAttribute, "Value Two==button" }, webDriver ).get( "RESULT" ) );
    stopStep( testName, StepStatus.SUCCESS, null );
    dumpState( webDriver, "afterAttribute", 5, 50 );
    
    startStep( testName, "Step Three", "Testing Wait For" );
    Assert.assertFalse( webDriver.findElement( By.id( "deleteButton" ) ).isDisplayed() );
    webDriver.findElement( By.xpath( "//div[@id='aOpen']//a" ) ).click();
    Assert.assertTrue( new WebDriverWait( webDriver, 12 ).ignoring( NotFoundException.class ).until( ExpectedConditions.visibilityOfElementLocated( By.id( "deleteButton" ) ) ).isDisplayed() );
    stopStep( testName, StepStatus.SUCCESS, null );
    dumpState( webDriver, "afterWaitFor", 2, 50 );

}
 
Example #19
Source File: HtmlNavigator.java    From ats-framework with Apache License 2.0 4 votes vote down vote up
@PublicAtsApi
public void navigateToFrame(
                             WebDriver webDriver,
                             UiElement element ) {

    if (lastWebDriver != webDriver) {
        // this is a new WebDriver instance
        lastWebDriver = webDriver;
        lastFramesLocation = "";
    }

    String newFramesLocationProperty = element != null
                                                       ? element.getElementProperty("frame")
                                                       : null;
    try {
        if (newFramesLocationProperty == null) {
            // No frame selection. Go to top frame if not there yet
            if (!"".equals(lastFramesLocation)) {
                log.debug("Go to TOP frame");
                webDriver.switchTo().defaultContent();
                lastFramesLocation = "";
            }
        } else {
            lastFramesLocation = newFramesLocationProperty;
            log.debug("Go to frame: " + newFramesLocationProperty);

            String[] newFramesLocation = newFramesLocationProperty.split("\\->");
            webDriver.switchTo().defaultContent();

            for (String frame : newFramesLocation) {

                if (frame.startsWith("/") || frame.startsWith("(/")) {

                    WebElement frameElement = webDriver.findElement(By.xpath(frame.trim()));
                    webDriver.switchTo().frame(frameElement);
                } else {

                    webDriver.switchTo().frame(frame.trim());
                }
            }
        }
    } catch (NotFoundException nfe) {

        String msg = "Frame not found. Searched by: '"
                     + (element != null
                                        ? element.getElementProperty("frame")
                                        : "")
                     + "'";
        log.debug(msg);
        throw new ElementNotFoundException(msg, nfe);
    }
}
 
Example #20
Source File: SearchContextWait.java    From Selenium-Foundation with Apache License 2.0 3 votes vote down vote up
/**
 * Wait will ignore instances of NotFoundException that are encountered
 * (thrown) by default in the 'until' condition, and immediately propagate
 * all others. You can add more to the ignore list by calling
 * ignoring(exceptions to add).
 *
 * @param context
 *            The SearchContext instance to pass to the expected conditions
 * @param timeOutInSeconds
 *            The timeout in seconds when an expectation is called
 * @param sleepInMillis
 *            The duration in milliseconds to sleep between polls.
 * @see SearchContextWait#ignoring(java.lang.Class)
 */
public SearchContextWait(final SearchContext context, final long timeOutInSeconds, final long sleepInMillis) {
    super(context);
    withTimeout(timeOutInSeconds, TimeUnit.SECONDS);
    pollingEvery(sleepInMillis, TimeUnit.MILLISECONDS);
    ignoring(NotFoundException.class);
    this.context = context;
}