2016-05-24 55 views
0

我正在测试一个窗口小部件,为了获取行车路线,我必须输入from(van)和To(naar)字段。输入和输出字段为javascript并在输入3个字符后自动完成。在选择了一个位置之后,我想声明所选位置确实在“收件人”或“发件人”字段中。但是,如果我尝试用assertEquals脚本来声明它,它告诉我该字段中没有数据。以下是我用来测试它的一些页面代码和代码。无法断言我刚刚填充的字段

enter image description here

这是HTML代码输入字段:

<input id="van" class="textfield" type="text" data-reactid=".0.1.1.0.1.0.0.1.0" value="" tabindex="0" required="" placeholder="Place" autocomplete="off" aria-label="Van"></input> 

这是我的文本输入到输入框,然后选择第二个可用的选项:

driver.findElement (By.id( “货车”))明确(); sendKeys(Ams);

driver.findElement(By.id(“van”))。sendKeys(Ams);

现在我展示含有阿姆斯特丹几个选项,我选择第二个选项:

driver.findElement(By.xpath(“// DIV [@类= '自动完成,下拉']/ul/li 2“))。click();

如果我看着屏幕,现在让我看到下面

enter image description here

我现在想断言从字段包含什么,我只是选择(阿姆斯特丹,北荷兰省)。我用下面这样做:

assertEquals(“Amsterdam,Noord-Holland”,driver.findElement(By.id(“van”)).getText());

在此然而结果:

org.junit.ComparisonFailure:预期:< [阿姆斯特丹,北荷兰省]>却被:< []>

,如果我检查它显示给我的元素:

<input id="van" class="textfield" type="text" data-reactid=".0.1.1.0.1.0.0.1.0" value="" tabindex="0" required="" placeholder="Place" autocomplete="off" aria-label="Van"></input> 

所以看起来ComparisonFailure是corr但我找不到为什么我不能断言我在屏幕上看到的东西。

我使用Java,Selenium和Eclipse进行测试。

+0

尝试: Webelement A = driver.findElement(通过。的xpath( “// DIV [@类= '自动完成-下拉']/UL/LI2”)); String b = a.gettext(); assertEquals(“Amsterdam,Noord-Holland”,b); –

回答

1

你好,请做如下图所示

在断言做这样

driver.findElement(By.id("van")).getAttribute("value"); 

// please note when you want 
to check the value entered by you inside the input box then do not use getText() 
as it returns inner visible html of the tag 
So to get the value there is a hidden attribute for every input box known as "value" 
which keeps value entered by you. 

希望这有助于你感谢

+0

谢谢,我没有意识到任何隐藏的属性,因为属性值是空的,我没有想到要检查它。这现在就像一个魅力 – Hugo

+0

你的欢迎,我很高兴它帮助你 –

相关问题