Selenium WebElement value empty after sending keys

谁说胖子不能爱 提交于 2019-12-10 15:17:05

问题


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 sending 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.


回答1:


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
}


来源:https://stackoverflow.com/questions/7272700/selenium-webelement-value-empty-after-sending-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!