我正在测试一个窗口小部件,为了获取行车路线,我必须输入from(van)和To(naar)字段。输入和输出字段为javascript并在输入3个字符后自动完成。在选择了一个位置之后,我想声明所选位置确实在“收件人”或“发件人”字段中。但是,如果我尝试用assertEquals脚本来声明它,它告诉我该字段中没有数据。以下是我用来测试它的一些页面代码和代码。无法断言我刚刚填充的字段
这是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();
如果我看着屏幕,现在让我看到下面
我现在想断言从字段包含什么,我只是选择(阿姆斯特丹,北荷兰省)。我用下面这样做:
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进行测试。
尝试: Webelement A = driver.findElement(通过。的xpath( “// DIV [@类= '自动完成-下拉']/UL/LI2”)); String b = a.gettext(); assertEquals(“Amsterdam,Noord-Holland”,b); –