use of org.openqa.selenium.NoSuchElementException in project carina by zebrunner.
the class DriverHelper method waitUntil.
/**
* Wait until any condition happens.
*
* @param condition - ExpectedCondition.
* @param timeout - timeout.
* @return true if condition happen.
*/
public boolean waitUntil(ExpectedCondition<?> condition, long timeout) {
boolean result;
long startMillis = 0;
final WebDriver drv = getDriver();
Wait<WebDriver> wait = new WebDriverWait(drv, timeout, RETRY_TIME).ignoring(WebDriverException.class).ignoring(NoSuchSessionException.class);
try {
startMillis = System.currentTimeMillis();
wait.until(condition);
result = true;
LOGGER.debug("waitUntil: finished true...");
} catch (NoSuchElementException | TimeoutException e) {
// don't write exception even in debug mode
LOGGER.debug("waitUntil: NoSuchElementException | TimeoutException e..." + condition.toString());
result = false;
} catch (Exception e) {
LOGGER.error("waitUntil: " + condition.toString(), e);
result = false;
} finally {
long timePassed = System.currentTimeMillis() - startMillis;
// timePassed is time in ms timeout in sec so we have to adjust
if (timePassed > 2 * timeout * 1000) {
LOGGER.error("Your retry_interval is too low: " + RETRY_TIME + " ms! Increase it or upgrade your hardware");
}
}
return result;
}
use of org.openqa.selenium.NoSuchElementException in project carina by zebrunner.
the class IAndroidUtils method scroll.
/**
* Scrolls into view in specified container
*
* @param scrollToEle
* - has to be id, text, contentDesc or className
* @param scrollableContainer
* - ExtendedWebElement type
* @param containerSelectorType
* - container Selector type: has to be id, text, textContains,
* textStartsWith, Description, DescriptionContains or className
* @param eleSelectorType
* - scrollToEle Selector type: has to be id, text, textContains,
* textStartsWith, Description, DescriptionContains or className
* @return ExtendedWebElement
* <p>
* example of usage: ExtendedWebElement res =
* AndroidUtils.scroll("News", newsListContainer,
* AndroidUtils.SelectorType.CLASS_NAME,
* AndroidUtils.SelectorType.TEXT);
*/
public default ExtendedWebElement scroll(String scrollToEle, ExtendedWebElement scrollableContainer, SelectorType containerSelectorType, SelectorType eleSelectorType) {
ExtendedWebElement extendedWebElement = null;
long startTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
// TODO: support multi threaded WebDriver's removing DriverPool usage
WebDriver drv = castDriver();
// workaorund for appium issue: https://github.com/appium/appium/issues/10159
if (scrollToEle.contains(",")) {
scrollToEle = StringUtils.join(StringUtils.split(scrollToEle, ","), ",", 0, 2);
if (eleSelectorType.equals(SelectorType.TEXT)) {
eleSelectorType = SelectorType.TEXT_CONTAINS;
}
}
for (int i = 0; i < SCROLL_MAX_SEARCH_SWIPES; i++) {
try {
By scrollBy = MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ")" + ".setMaxSearchSwipes(" + SCROLL_MAX_SEARCH_SWIPES + ")" + ".scrollIntoView(" + getScrollToElementSelector(scrollToEle, eleSelectorType) + ")");
WebElement ele = drv.findElement(scrollBy);
if (ele.isDisplayed()) {
UTILS_LOGGER.info("Element found!!!");
extendedWebElement = new ExtendedWebElement(scrollBy, scrollToEle, drv);
break;
}
} catch (NoSuchElementException noSuchElement) {
UTILS_LOGGER.error(String.format("Element %s:%s was NOT found.", eleSelectorType, scrollToEle), noSuchElement);
}
for (int j = 0; j < i; j++) {
checkTimeout(startTime);
MobileBy.AndroidUIAutomator("new UiScrollable(" + getScrollContainerSelector(scrollableContainer, containerSelectorType) + ").scrollForward()");
UTILS_LOGGER.info("Scroller got stuck on a page, scrolling forward to next page of elements..");
}
}
return extendedWebElement;
}
use of org.openqa.selenium.NoSuchElementException in project testsigma by testsigmahq.
the class SelectOptionByValueAction method execute.
@Override
protected void execute() throws Exception {
findElement();
Select selectElement = new Select(getElement());
try {
selectElement.selectByValue(getTestData());
setSuccessMessage(SUCCESS_MESSAGE);
} catch (NoSuchElementException e) {
throw new AutomatorException(String.format(FAILURE_MESSAGE, getTestData(), getFindByType(), getLocatorValue(), getTestData()));
}
}
use of org.openqa.selenium.NoSuchElementException in project testsigma by testsigmahq.
the class SelectOptionByVisibleTextAction method execute.
@Override
protected void execute() throws Exception {
try {
findElement();
Select selectElement = new Select(getElement());
selectElement.selectByVisibleText(getTestData());
setSuccessMessage(SUCCESS_MESSAGE);
} catch (NoSuchElementException e) {
throw new AutomatorException(String.format(FAILURE_MESSAGE, getTestData(), getFindByType(), getLocatorValue(), getTestData()));
}
}
use of org.openqa.selenium.NoSuchElementException in project healenium-example-maven by healenium.
the class MarkupPage method selectAllCheckboxes.
public int selectAllCheckboxes() {
List<WebElement> checkboxes = driver.findElements(checkboxAccount);
if (checkboxes.size() == 0)
throw new NoSuchElementException("No checkboxes found");
checkboxes.forEach(c -> c.click());
return checkboxes.size();
}
Aggregations