2

我有一个场景,其中有一个文本框,当我在该文本框中键入内容时,它会自动填充。我需要跟踪自动填充的值并验证它是否包含我在文本字段中输入的字符串。有人可以帮我解决这个问题吗?提前致谢

4

3 回答 3

1

尝试这样的事情

下面的代码用于获取谷歌网站的自动填充结果。

driver.get("http://www.google.co.in");
driver.findElement(By.id("lst-ib")).sendKeys("Test");
List<WebElement> autoPopulatedList=driver.findElements(By.cssSelector("tr>td>span"));
for(WebElement ele:autoPopulatedList)
{
      System.out.println(ele.getText());
      if(ele.getText().contains("Test"))
      {
             System.out.println("Your case passed..!!");
      }
}
于 2013-01-29T06:22:12.287 回答
0

只需发送文本抛出 Sendkey ,然后像这样获取字段值:

    driver.findElement(By.id("field ID here")).sendkeys("ABC");
    String strActualValue = driver.findElement(By.id("field ID here")).getAttribute("value");
    System.out.println("Field value is = "+strActualValue +"");

它将打印您通过发送键发送的值以及在字段中自动填充的值。

    Result : ABC1234
    ABC is your value 1234 is auto-populated value.

请享用!

于 2014-02-06T05:08:28.393 回答
0
driver.get(URL); // URL = http://www.google.co.in;

driver.findElement(By.id(id_of_the_element)).sendKeys(value); //Value for the field

List autoPopulatedList=driver.findElements(auto_populate_element_path);

int autoPopulateSize = autoPopulatedList.length(); // Take the auto populate size to compare

int testedSize = 0; //initialize a variable for testing

for(WebElement element : autoPopulatedList){

     if(element.getText().contains(value)) //Checking the autopopulated list with the value

     {

           testedSize++;  // this will add 1 if the autopopulate contains the value

     }

}

if(autoPopulateSize == testedSize){

     System.out.println("Autopopulate contains the values");
}else{

 System.out.println("Fail");
}
于 2014-01-16T10:20:35.723 回答