Search in sources :

Example 1 with BFElementNotFoundException

use of com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException in project devonfw-testing by devonfw.

the class JsoupHelper method getElements.

private static List<WebElement> getElements(String text, List<String> selectors) {
    if (selectors.isEmpty()) {
        throw new BFElementNotFoundException("Element with text [" + text + "] not found.");
    }
    List<WebElement> elementsToReturn = new ArrayList<WebElement>();
    for (String selector : selectors) {
        By elementSelector = By.cssSelector(selector);
        @SuppressWarnings("deprecation") WebElement foundElement = BasePage.getDriver().findElement(elementSelector);
        elementsToReturn.add(foundElement);
    }
    return elementsToReturn;
}
Also used : BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) By(org.openqa.selenium.By) ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement)

Example 2 with BFElementNotFoundException

use of com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException in project devonfw-testing by devonfw.

the class NewChromeDriver method findElement.

/**
 * @deprecated As of release 1.0.0, replaced by {@link #findElementDynamic(By)()}
 */
@Deprecated
@Override
public WebElement findElement(By by) throws BFElementNotFoundException {
    BaseTest.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    WebElement elementFromDriver = null;
    try {
        elementFromDriver = super.findElement(by);
    } catch (NoSuchElementException e) {
        throw new BFElementNotFoundException(by);
    }
    return new NewRemoteWebElement(elementFromDriver);
}
Also used : BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 3 with BFElementNotFoundException

use of com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException in project devonfw-testing by devonfw.

the class NewInternetExplorerDriver method findElement.

/**
 * @deprecated As of release 1.0.0, replaced by {@link #findElementDynamic(By)()}
 */
@Deprecated
@Override
public WebElement findElement(By by) throws BFElementNotFoundException {
    BasePage.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    WebElement elementFromDriver = null;
    try {
        elementFromDriver = super.findElement(by);
    } catch (NoSuchElementException e) {
        throw new BFElementNotFoundException(by);
    }
    return new NewRemoteWebElement(elementFromDriver);
}
Also used : BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 4 with BFElementNotFoundException

use of com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException in project devonfw-testing by devonfw.

the class ElementPositionUtils method isElementsPositionRelatedX.

/**
 * Method checks if second element is in given relation to first element considering X coordinate
 *
 * @param selectorFirst
 *            By object with an selector
 * @param selectorSecond
 *            By object with an selector
 * @param scope
 *            WebElement which contains comparing objects
 * @param position
 *            relation of a second element to first one
 * @return true if two elements are placed in given relation
 * @throws BFElementNotFoundException
 *             if elements do not exist
 */
public static boolean isElementsPositionRelatedX(By selectorFirst, By selectorSecond, WebElement scope, RelatedPositionEnum position) {
    @SuppressWarnings("deprecation") WebElement elementFirst = BasePage.getDriver().findElementQuietly(scope, selectorFirst);
    @SuppressWarnings("deprecation") WebElement elementSecond = BasePage.getDriver().findElementQuietly(scope, selectorSecond);
    if (elementFirst == null) {
        throw new BFElementNotFoundException(selectorFirst);
    }
    if (elementSecond == null) {
        throw new BFElementNotFoundException(selectorSecond);
    }
    return ElementPositionUtils.isElementsPositionRelatedX(elementFirst, elementSecond, position);
}
Also used : BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement)

Example 5 with BFElementNotFoundException

use of com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException in project devonfw-testing by devonfw.

the class DriverExtention method waitForElement.

public WebElement waitForElement(final By by) throws BFElementNotFoundException {
    BasePage.getAnalytics().sendMethodEvent(BasePage.analitycsCategoryName);
    long startTime = System.currentTimeMillis();
    WebElement element = null;
    FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver);
    wait.pollingEvery(250, TimeUnit.MILLISECONDS);
    wait.withTimeout(2, TimeUnit.MINUTES);
    try {
        element = webDriverWait().until(new Function<WebDriver, WebElement>() {

            @Override
            public WebElement apply(WebDriver driver) {
                return driver.findElement(by);
            }
        });
    } catch (TimeoutException | NoSuchElementException e) {
        boolean isTimeout = true;
        throw new BFElementNotFoundException(by, isTimeout, BasePage.EXPLICITYWAITTIMER);
    }
    BFLogger.logTime(startTime, "waitForElement()", by.toString());
    return element;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Function(java.util.function.Function) FluentWait(org.openqa.selenium.support.ui.FluentWait) BFElementNotFoundException(com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

Aggregations

BFElementNotFoundException (com.capgemini.mrchecker.selenium.core.exceptions.BFElementNotFoundException)12 WebElement (org.openqa.selenium.WebElement)11 NoSuchElementException (org.openqa.selenium.NoSuchElementException)9 TimeoutException (org.openqa.selenium.TimeoutException)6 WebDriver (org.openqa.selenium.WebDriver)6 Function (java.util.function.Function)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)3 ArrayList (java.util.ArrayList)2 By (org.openqa.selenium.By)1 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)1 FluentWait (org.openqa.selenium.support.ui.FluentWait)1