actually i want to get an element with the @FindBy
that is use into the Page Objects pattern.
I've 2 classes, the 1st one is my page objects named TestPage
and the 2nd one is named PageSaveTest
(where my tests happen and call the TestPage
).
I've also tried to use the @FindBy
with xpath
and id
.
>> This is my TestPage
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
public class TestPage {
// get autocomplete input
@FindBy(css = "input[id*='supplierOps_input']")
private WebElement autocompleteSupplierOps;
// getter
public WebElement getAutocompleteSupplierOps() {
return autocompleteSupplierOps;
}
}
>> This is my PageSaveTest
// How i "inject" my TestPage
@Page
TestPage testpage;
[...]
// My test
WebElement autocomplete = testpage.getAutocompleteSupplierOps();
String keys = "OP";
autocomplete.sendKeys(keys); // >>>>>>> Error throwed here !
List<WebElement> listSugg = testpage.getSuggestionsSupplierOps();
Error message :
org.openqa.selenium.NoSuchElementException : Returned node was not an HTML element.
My thoughts :
I think the trouble comes from the @FindBy
. But i use this example to build my TestPage and my test and this one too.
Question : Can someone explain to me how @FindBy
works and be used in my example ? The documentation is really poor about Graphene.
EDIT :
I've modify my getter in TestPage (above), i've tried a simple print of the id attribute value like
public WebElement getAutocompleteSupplierOps() {
System.out.println(">>>> "+autocompleteSupplierOps.getAttribute("id"));
return autocompleteSupplierOps;
}
But still the same error, the @FindBy
is f*cked up.
Another @FindBy spec to add in this issue.
Update :
I've fixed my selector but actually there is a probleme with the driver session like :
page2.getAutocompleteSupplierOps();
PAGE 1 ----------------------------------> PAGE 2
driver id:1 ----------------------------------> driver id:2
driver.showPageSource() is empty
return no element found <---------------------- driver.findElement() -> not found
I've used 3 different ways, the @FindBy
, the @Drone WebDriver
and finally what @Lukas Fryc
suggested to me.