下面列出了org.openqa.selenium.interactions.Locatable#org.openqa.selenium.internal.WrapsElement 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public WebElement apply(final WebElement element) {
return (WebElement) newProxyInstance(
getClass().getClassLoader(),
new Class[]{WebElement.class, WrapsElement.class, Locatable.class, HasIdentity.class},
invocationHandlerFor(element)
);
}
/**
* Returns a 'wait' proxy that determines if the specified element reference has gone stale.
*
* @param element the element to wait for
* @return 'false' if the element reference is still valid; otherwise 'true'
*/
public static Coordinator<Boolean> stalenessOf(final WebElement element) {
return new Coordinator<Boolean>() {
private final ExpectedCondition<Boolean> condition = conditionInitializer();
// initializer for [condition] field
private final ExpectedCondition<Boolean> conditionInitializer() {
if (element instanceof WrapsElement) {
return ExpectedConditions.stalenessOf(((WrapsElement) element).getWrappedElement());
} else {
return ExpectedConditions.stalenessOf(element);
}
}
/**
* {@inheritDoc}
*/
@Override
public Boolean apply(final SearchContext ignored) {
return condition.apply(null);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return condition.toString();
}
/**
* {@inheritDoc}
*/
@Override
public TimeoutException differentiateTimeout(TimeoutException e) {
return new ElementStillFreshTimeoutException(e.getMessage(), e.getCause());
}
};
}
/**
* Assert that the two elements are equal.
* <p>
* Can be removed if https://dev.vaadin.com/ticket/18484 is fixed.
*
* @param expectedElement
* the expected element
* @param actualElement
* the actual element
*/
protected static void assertEquals(WebElement expectedElement,
WebElement actualElement) {
WebElement unwrappedExpected = expectedElement;
WebElement unwrappedActual = actualElement;
while (unwrappedExpected instanceof WrapsElement) {
unwrappedExpected = ((WrapsElement) unwrappedExpected)
.getWrappedElement();
}
while (unwrappedActual instanceof WrapsElement) {
unwrappedActual = ((WrapsElement) unwrappedActual)
.getWrappedElement();
}
Assert.assertEquals(unwrappedExpected, unwrappedActual);
}
protected ExtendedWebElement proxyForLocator(ClassLoader loader, Field field, ElementLocator locator) {
InvocationHandler handler = new LocatingElementHandler(locator);
WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class },
handler);
return new ExtendedWebElement(proxy, field.getName(),
field.isAnnotationPresent(FindBy.class) || field.isAnnotationPresent(ExtendedFindBy.class)? new LocalizedAnnotations(field).buildBy() : null);
}
public static <T extends WebElement> T createWebElementProxy(ClassLoader loader, InvocationHandler handler) {
Class<?>[] interfaces = new Class[]{WebElement.class, WrapsElement.class, Locatable.class};
return (T) Proxy.newProxyInstance(loader, interfaces, handler);
}
private WebElement getWebElementFromFactory(ElementLocatorFactory factory) {
InvocationHandler handler = new LocatingElementHandler(
((ParentElementLocatorProvider) factory).getCurrentScope());
return (WebElement) Proxy.newProxyInstance(WebElement.class.getClassLoader(),
new Class[] {WebElement.class, WrapsElement.class, Locatable.class}, handler);
}