首页 文章

无法断言我刚刚填写的字段

提问于
浏览
0

我正在测试一个小部件,我必须输入一个从(van)和To(naar)字段才能获得旅行指示 . 键入3个字符后,“收件人”和“自”字段为javascript并自动完成 . 选择了一个位置后,我想断言所选位置确实在To或From字段中 . 但是,如果我尝试使用assertEquals脚本断言它,它会告诉我该字段中没有数据 . 这是我用来测试它的一些页面代码和代码 .

enter image description here

这是html From输入字段:

<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(“van”)) . clear(); driver.findElement(By.id( “货车”))的SendKeys(AMS) .

它现在向我展示了包含阿姆斯特丹的几个选项,我选择了第二个选项:

driver.findElement(By.xpath(“// div [@ class ='autocomplete-dropdown'] / ul / li2”)) . click();

如果我看屏幕,它现在显示以下内容

enter image description here

我现在想断言From字段包含我刚刚选择的内容(Amsterdam,Noord-Holland) . 我这样做有以下几点:

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

然而,这导致:

org.junit.ComparisonFailure:预期:<[Amsterdam,Noord-Holland]>但是:<[]>

如果我检查元素它会告诉我:

<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是正确的但我无法找出为什么我不能断言我在屏幕上看到的内容 .

我正在使用Java,Selenium和Eclipse进行测试 .

1 回答

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

    希望这可以帮助你谢谢

相关问题