发送密钥后,Selenium WebElement值为空 [英] 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);
我要检查字段中的值是否正确.这听起来可能很不正常,但该字段可能附加了ajax搜索,如果搜索没有拉回匹配项,则该字段将为空.
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.
发送密钥后,我尝试测试WebElement的文本值,但它似乎总是空的:
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
我正在将Selenium 2与WebDriver一起使用-还有另一种方法来执行这些检查吗?即使SendKeys成功将值(实际上是在浏览器中)打印到WebElement(文本框)中,WebElement是否为空,还是有特定的原因吗?
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)?
任何帮助将不胜感激.
推荐答案
输入的文本值可能被分配为文本框的值"属性,而不是文本"
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
}
这篇关于发送密钥后,Selenium WebElement值为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!