For example: we have such element in web page:
<input id="input1" class="timeField" type="text"/>
// typing "Eng"
element.sendKeys(textToInput.substring(0,3));
// text == "" - empty string
String text = element.getText();
// correct way to check text(value) in input element:
//text == "Eng"
text = element.getAttribute("value");
//typing "lish"
element.sendKeys(textToInput.substring(3));
// text == "" - empty string
text = element.getText();
// text = "English"
text = element.getAttribute("value");
<input id="input1" class="timeField" type="text"/>
WebElement element = driver.findElement(By.cssSelector(".timeField"));
String textToInput = "English";
//we can easily read its' initial value by:
String initalText = element.getText();
//but if you type something and try to get text you will get empty string
//removing initial value in "input"
element.clear();
String textToInput = "English";
//we can easily read its' initial value by:
String initalText = element.getText();
//but if you type something and try to get text you will get empty string
//removing initial value in "input"
element.clear();
// typing "Eng"
element.sendKeys(textToInput.substring(0,3));
// text == "" - empty string
String text = element.getText();
// correct way to check text(value) in input element:
//text == "Eng"
text = element.getAttribute("value");
//typing "lish"
element.sendKeys(textToInput.substring(3));
// text == "" - empty string
text = element.getText();
// text = "English"
text = element.getAttribute("value");
Comments
Post a Comment