テキスト ボックスがあり、そのテキスト ボックスに何かを入力すると自動入力されるシナリオがあります。自動入力された値をトレースし、テキスト フィールドに入力した文字列が含まれていることを確認する必要があります。誰かがこれで私を助けてくれますか? 前もって感謝します
質問する
4905 次
3 に答える
1
このようなものを試してください
以下のコードは、Googleサイトの自動入力結果を取得するためのものです。
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
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 に答える