Access @FindBy information on WebElement

12 views
Skip to the first unread message

Robert Mark Bram

unread,
26 Mar 2015, 00:49:1426/03/2015
to seleniu...@googlegroups.com

Hi All,

If I am using Selenium's @FindBy annotations to specify an id or xpath to look for (on an object that will later go through PageFactory.initElements(driver, this);), is there any way I can output that information for debugging purposes?

For example, I have defined my fields...

@FindBy(id = "someId")
private WebElement someElement;

And created utility methods to manipulate those fields, such as

public void clickOnElement(WebElement element) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Will click on element [" + element.getTagName() + "].");
    }
    waitForClickableElement(element); // Uses FluentWait..
    element.click();
}

The call to element.getTagName() is preemptive and fragile above, because I am doing something that will access the field before I get a chance to even check if the field is present, let alone clickable. So, is there a way instead to access the @FindBy information to output debugging information?

Rob

:)

Reply all
Reply to author
Forward
0 new messages