Selenium WebElement is empty after sending keys

I run some simple form tests in which values ​​are added.

After each value is added to the field:

input.SendKeys(value); 

I want to check the correctness of the value in the field. This may seem unusual, but an ajax search may be included in the field, and if the search does not cancel the match, the field will be empty.

I tried to test the text value of WebElement after sending the keys, but it always seems empty:

 bool match = input.Text.Equals(value); // input.Text always seems to be an empty string 

I am using Selenium 2 with WebDriver - is there any other way to perform these checks? Is there a special reason why the WebElement is empty, even if SendKeys successfully prints the value (actually in the browser) to the WebElement (text field)?

Any help would be greatly appreciated.

+4
source share
1 answer

It is possible that the text value you enter is assigned as the attribute "value" of the text field, and not as "text"

 input.sendKeys(enteredValue) String retrievedText = input.getAttribute("value"); if(retrievedText.equals(enteredValue)){ //do stuff } 
+8
source

All Articles