use of org.openqa.selenium.NoSuchFrameException in project selenide by selenide.
the class FrameByIdOrNameTest method apply_shouldIgnore_noSuchFrameException.
@Test
void apply_shouldIgnore_noSuchFrameException() {
WebDriver webdriver = mock(WebDriver.class);
doThrow(new NoSuchFrameException("No frame element found by name or id paymentFrame")).when(webdriver).findElement(any());
assertThat(new FrameByIdOrName("paymentFrame").apply(webdriver)).isNull();
}
use of org.openqa.selenium.NoSuchFrameException in project sentinel by dougnoel.
the class Element method findElementInIFrame.
/**
* Searches recursively through any iFrames on the page for the element. Returns
* null if the element is not found, or if there are no iFrames on the page. This
* method traverses through iFrames but returns to the default root context upon
* returning.
*
* @return WebElement the element if it is found, otherwise null
*/
protected WebElement findElementInIFrame() {
if (PageManager.getPage().hasIFrames()) {
WebElement element = null;
List<WebElement> iframes = PageManager.getPage().getIFrames();
try {
for (WebElement iframe : iframes) {
driver().switchTo().frame(iframe);
element = findElementInCurrentFrameForDuration(Time.loopInterval());
if (element != null) {
return element;
}
element = findElementInIFrame();
if (element != null)
return element;
driver().switchTo().parentFrame();
}
} catch (StaleElementReferenceException | NoSuchFrameException e) {
var errorMessage = SentinelStringUtils.format("Error when searching for {} element named \"{}\" while attempting to search through iFrames. Looping again. Error: {}", elementType, getName(), e);
log.trace(errorMessage);
return null;
}
}
return null;
}
use of org.openqa.selenium.NoSuchFrameException in project selenese-runner-java by vmi.
the class SelectFrame method executeImpl.
@Override
protected Result executeImpl(Context context, String... curArgs) {
String locator = curArgs[ARG_LOCATOR];
WebDriver driver = context.getWrappedDriver();
WebDriverElementFinder elementFinder = context.getElementFinder();
// ns
long timeout = context.getTimeout() * MILLI_TO_NANO;
long start = System.nanoTime();
while (true) {
try {
elementFinder.selectFrame(driver, locator);
return SUCCESS;
} catch (NoSuchFrameException e) {
if (System.nanoTime() - start > timeout) {
log.warn("Timed out select frame: {}", locator);
throw e;
}
}
Wait.sleep(RETRY_INTERVAL);
}
}
use of org.openqa.selenium.NoSuchFrameException in project seleniumRobot by bhecquet.
the class HtmlElement method enterFrame.
/**
* Method for going into the right frame before doing anything else this method
* should be called each time we need to get an element Therefore, it's used
* inside findElement() method
*/
private void enterFrame() {
List<FrameElement> frameTree = new ArrayList<>();
FrameElement frame = getFrameElement();
while (frame != null) {
frameTree.add(0, frame);
frame = frame.getFrameElement();
}
for (FrameElement frameEl : frameTree) {
Integer idx = frameEl.getElementIndex() == null ? 0 : frameEl.getElementIndex();
WebElement frameWebElement;
try {
frameWebElement = getDriver().findElements(frameEl.getBy()).get(idx);
} catch (IndexOutOfBoundsException e) {
throw new NoSuchFrameException(String.format("Frame %s with index %d has not been found", frameEl, idx));
}
((CustomEventFiringWebDriver) getDriver()).scrollToElement(frameWebElement, -20);
getDriver().switchTo().frame(frameWebElement);
}
}
use of org.openqa.selenium.NoSuchFrameException in project seleniumRobot by bhecquet.
the class SeleniumNativeActions method recordFrameSwitch.
/**
* Method interceptFindHtmlElement creates an HtmlElement from findElement, but does not handle frames.
* Here, we record all switchTo().frame(WebElement) call to create a FrameElement chain
* @param joinPoint
* @return
* @throws Throwable
*/
@Around(// caller is a PageObject
"this(com.seleniumtests.uipage.PageObject) && " + "(call(public * org.openqa.selenium.support.ui.ExpectedConditions.frameToBeAvailableAndSwitchToIt (..))" + ")")
public Object recordFrameSwitch(ProceedingJoinPoint joinPoint) throws Throwable {
if (Boolean.TRUE.equals(doOverride())) {
Object frameArg = joinPoint.getArgs()[0];
FrameElement frameEl = getFrameElement(frameArg);
if (frameEl == null) {
return joinPoint.proceed(joinPoint.getArgs());
}
if (getCurrentFrame() == null) {
setCurrentFrame(frameEl);
} else {
frameEl.setFrameElement(getCurrentFrame());
setCurrentFrame(frameEl);
}
return new ExpectedCondition<WebDriver>() {
@Override
public WebDriver apply(WebDriver driver) {
try {
return driver;
} catch (NoSuchFrameException e) {
return null;
}
}
@Override
public String toString() {
return "frame to be available: " + frameArg;
}
};
} else {
return joinPoint.proceed(joinPoint.getArgs());
}
}
Aggregations