I have a class with the following public instance variable
@FindBy(id="titleInput")
public WebElement titleInputBox;
Then I use page factory in the constructor to initialize it on every use
PageFactory.initElements(driver, this);
In my test case for this page, I use the following code to test whether the text I sent is actually getting set in the field ...
subtitleInputBox.sendKeys("Test");
subtitleInputBox.getText();
and I get empty string
any idea why this happens ... I think it works fine if driver.findElement()
is used directly without @FindBy
and PageFactory
To get the text out of an input box like text or textarea you need to use the getAttribute("value")
method. getText()
works for tags like div, span etc etc.
subtitleInputBox.getAttribute("value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With