简体   繁体   中英

Using @FindBy to find WebElementS

We have a list of elements specified by "//input[contains(@name,'smcNetwork')]". I am used to finding a webelement like

 @FindBy(xpath = "//*[id='myId']")  private WebElement myelement;

But, as per subject the xpath I mentioned returns an array (or list I guess) where I would do

List<WebElement> networks = driver.findElementsBy( xpath = "//input[contains(@name,'smcNetwork')]")

I would like to do this in a FindBy but it did not seem to work:

@FindBy( xpath = "//input[contains(@name,'smcNetwork')]") private List<WebElement> networks;

but that was returning null. Can you do this somehow?

You can do something like this.

@FindAll({@FindBy(xpath = "yourpath")})
public List<WebElement> networks;

To locate web element using @FindBy , you can use below snippet

@FindBy(xpath = "xpathValue")
private static WebElement xpathName;

here, you can change access level by making it as public or private/protected.

If you are making it as private then use this locator within that class and define a common method as public.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM