开发者

Selenium WebElement value empty after sending keys

I'm running some simple form tests where values are added fields.

After each value is added to a field:

input.SendKeys(value);

I want to check the value in the field is correct. This may sound unusual but the field may have an ajax search attached and if the search doesn't pull back a match, the field will be empty.

I've tried testing the text value of the WebElement after sendi开发者_C百科ng the keys but it always seems to be empty:

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

I'm using Selenium 2 with the WebDriver - is there another way to perform these checks? Is there a particular reason why the WebElement is empty even if the SendKeys successfully prints a value (actually in the browser) in to the WebElement (textbox)?

Any help would be grateful.


It may be possible that the text value that you are entering is assigned as a "value" attribute of text box and not as "text"

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜