use of org.openqa.selenium.support.pagefactory.DefaultElementLocator in project seleniumRobot by bhecquet.
the class SeleniumNativeActions method interceptPageFactoryElementsLocation.
/**
* Intercept "findElements" action done in LocatingElementListHandler class so that we can override returned element and replace it by HtmlElement
* This helps handling PageObjectFactory method
* @param joinPoint
* @return
* @throws Throwable
*/
@Around(" this(org.openqa.selenium.support.pagefactory.internal.LocatingElementListHandler) && call(public * org.openqa.selenium.support.pagefactory.ElementLocator+.findElements (..))")
public Object interceptPageFactoryElementsLocation(ProceedingJoinPoint joinPoint) throws Throwable {
if (doOverride()) {
DefaultElementLocator locator = ((DefaultElementLocator) joinPoint.getTarget());
Field byField = DefaultElementLocator.class.getDeclaredField("by");
byField.setAccessible(true);
return new HtmlElement("", (By) byField.get(locator), getCurrentFrame()).findElements();
} else {
return joinPoint.proceed(joinPoint.getArgs());
}
}
use of org.openqa.selenium.support.pagefactory.DefaultElementLocator in project seleniumRobot by bhecquet.
the class SeleniumNativeActions method interceptPageFactoryElementLocation.
/**
* Intercept "findElement" action done in LocatingElementHandler class so that we can override returned element and replace it by HtmlElement
* This helps handling PageObjectFactory method
* @param joinPoint
* @return
* @throws Throwable
*/
@Around(" this(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) && call(public * org.openqa.selenium.support.pagefactory.ElementLocator+.findElement (..))")
public Object interceptPageFactoryElementLocation(ProceedingJoinPoint joinPoint) throws Throwable {
if (Boolean.TRUE.equals(doOverride())) {
DefaultElementLocator locator = ((DefaultElementLocator) joinPoint.getTarget());
Field byField = DefaultElementLocator.class.getDeclaredField("by");
byField.setAccessible(true);
return new HtmlElement("", (By) byField.get(locator), getCurrentFrame());
} else {
return joinPoint.proceed(joinPoint.getArgs());
}
}
use of org.openqa.selenium.support.pagefactory.DefaultElementLocator in project seleniumRobot by bhecquet.
the class SeleniumNativeActions method getFrameElement.
/**
* Returns a FrameElement based on the object passed in argument
* @param frameArg
* @return
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
private FrameElement getFrameElement(Object frameArg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
FrameElement frameEl = null;
if (frameArg instanceof HtmlElement) {
frameEl = new FrameElement("", ((HtmlElement) frameArg).getBy());
} else if (frameArg instanceof WebElement && frameArg.getClass().getName().contains("Proxy")) {
LocatingElementHandler locatingEh = (LocatingElementHandler) Proxy.getInvocationHandler(frameArg);
Field locatorField = LocatingElementHandler.class.getDeclaredField("locator");
locatorField.setAccessible(true);
DefaultElementLocator locator = ((DefaultElementLocator) locatorField.get(locatingEh));
Field byField = DefaultElementLocator.class.getDeclaredField("by");
byField.setAccessible(true);
frameEl = new FrameElement("", (By) byField.get(locator));
} else if (frameArg instanceof By) {
frameEl = new FrameElement("", (By) frameArg);
} else if (frameArg instanceof Integer) {
frameEl = new FrameElement("", By.tagName("iframe"), (Integer) frameArg);
} else if (frameArg instanceof String) {
String name = ((String) frameArg).replaceAll("(['\"\\\\#.:;,!?+<>=~*^$|%&@`{}\\-/\\[\\]\\(\\)])", "\\\\$1");
frameEl = new FrameElement("", By.cssSelector("frame[name='" + name + "'],iframe[name='" + name + "'],frame#" + name + ",iframe#" + name));
}
return frameEl;
}
Aggregations