Java – How to specify multiple locators for Selenium web element using the FindBy and PageFactory mechanisms

javaseleniumselenium-webdriver

I like to use PageFactory with FindBy annotations in my automation framework to autolocate elements in my page object classes.

I have one WebElement for which I need to be able to specify a couple of different locators. I thought FindBys was my solution, but apparently that is not how it works. It's the equivalent of driver.findElement(option1).findelement.(option2). That's not what I need. I need something that will find an element by one or the other locators. If one doesn't work, then use the other locator. Is there a way to do this in Selenium using FindBy annotations?

Best Answer

Related Topic