TA的每日心情 | 开心 2015-6-11 11:04 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
请大家帮我看看这段脚本问题出在哪里呢?
public boolean checkSearchEndty(String keyword, String SearchBy) throws InterruptedException {
Library.menuBar(driver, "entity");
//select searchBy and input the keyword, click Search
new Select(driver.findElement(By.id("searchfield"))).selectByVisibleText(SearchBy);
lib.waitForElementDisplayed(driver, 3, By.id("view"));
driver.findElement(By.id("searchphrase")).sendKeys(keyword);
driver.findElement(By.linkText("Search")).click();
Thread.sleep(5000);
//verify search result found, if no search result found then stop
boolean isDisplayed = lib.waitForElementDisplayed(driver, 20, By.id("ListTable"));
boolean searchResult = false;
if (isDisplayed == false) {
searchResult = true;
driver.close();
return searchResult;
}
//verify search result found, if the search results are found then check the result
else {
//get the td number of SearchBy in the search result table,
List<WebElement> ths = driver.findElements(By.xpath("//table[@id='ListTable']/tbody/tr[1]/th"));
int totalCol = ths.size();
System.out.println("totalCol=" + totalCol);
int tdNum = 1;
for (int i = 1; i < totalCol; i++) {
if (ths.get(i).getText().trim().equals(SearchBy)) {
tdNum = i+1;
break;
}
else {
}
}
//based on the td number, verify each result in the select td for each row.
List<WebElement> trs = driver.findElements(By.xpath("//table[@id='ListTable']/tbody/tr[contains(@class,'grid_')]"));
int totalRow = trs.size();
for (int i = 2; i <= totalRow; i++) {
String actualText = trs.get(i).findElement(By.xpath("td["+tdNum+"]")).getText();
searchResult = Library.assertWaitForTrue(2, actualText.equals(keyword));
if (searchResult == false) {
break;
}
}
}
return searchResult;
}
}
报错
|
|