Reputation: 1
I have two forms on the page. Both of them have 10 fields to fill. I have selectors for these fields in a separate class and use @Findby annotation for them (selectors for these fields are the same across both forms). I came up with an idea that I would first find a list of the forms and then using "for" loop I would fill in all of the fields for each form. The problem is that if I use the field elements with annotation @Findby the fields in first form get filled twice. If I use Webelement element = form.findelement(By.cssSelector("blablabla"); element.sendKeys ("blabla) for each element in the for loop everything works. How can I approach this without droping the @Findby annotation for elements? I have tried using
for (WebElement form:forms){
Webelement field1 = form.findElement(By.cssSelector("blablabla");
element.sendKeys ("blabla);
}
and this works but I want to use here the locators that I have with @FindBy annotation. On those I cannot use form.findElement method. What should I do?
Upvotes: 0
Views: 23
Reputation: 1
If you really want to keep @FindBy annotation you could do as follows.
Assuming for each selector you will have two elements(since you have two forms)
@FindBy(css= "blablabla")
List< WebElement> elements;
elements.get(0).sendKeys ("blabla_form1");
elements.get(1).sendKeys ("blabla_form2");
Upvotes: 0