Simon
> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>
>
public class MyLocator implements ElementLocator {
private final WebDriver driver;
private final By by;
private final boolean shouldCache;
private WebElement cachedElement;
public MyLocator(WebDriver driver, Field field) {
this.driver = driver;
Annotations annotations = new Annotations(field)
shouldCache = annotations.isLookupCached();
MyFindBy findBy = field.getAnnotation(MyFindBy.class);
if (findBy != null) {
by = deriveFrom(findBy);
} else {
by = annotations.buildBy();
}
}
protected By deriveFrom(MyFindBy annotation) {
// your magic here
}
public WebElement findElement() {
if (cachedElement != null && shouldCache) {
return cachedElement;
}
WebElement element = driver.findElement(by);
if (shouldCache) {
cachedElement = element;
}
return element;
}
}
That's the hardest bit. The rest is up to you :)
Simon
On Thu, Nov 18, 2010 at 8:25 PM, confusa <materia...@gmail.com> wrote:
> Ahh, that makes sense. Should I implement the ElementLocatorFactory
> interface and create my custom locator that way? Seems like the proper
> thing to do perhaps.
>
> Thanks!
>
> Bryan
>
> On Nov 18, 9:09 am, Simon Stewart <simon.m.stew...@gmail.com> wrote:
>> Annotations are static. You can, however, pretty easily write a custom
>> ElementLocator that can build the By dynamically.
>>
>> Simon
>>
Simon
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+unsubscribe@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.