TA的每日心情 | 奋斗 2017-4-1 09:18 |
---|
签到天数: 6 天 连续签到: 2 天 [LV.2]测试排长
|
如图所示,想要遍历device type、device model、firmware name、firmware version这4列的值
代码如下:
@Test
public void test1() throws Exception {
String searchtext="gate";
driver.findElement(By.xpath("//input[@ng-model='search']")).clear();
driver.findElement(By.xpath("//input[@ng-model='search']")).sendKeys(searchtext);
driver.findElement(By.xpath("//button[@type='submit']")).click();
WebElement table = driver.findElement(By.tagName("table"));
int count = 0;
List<WebElement> rows = table.findElements(By.tagName("tr"));
for(WebElement row:rows){
List<WebElement> cols= row.findElements(By.tagName("td"));
for(WebElement col:cols){
Pattern pattern = Pattern.compile(searchtext,Pattern.CASE_INSENSITIVE);//大小写不敏感
Matcher matcher = pattern.matcher(col.getText());
if(matcher.find()){
System.out.println("第"+ row +"行:"+ col.getText());
count = count + 1;
break;
}
}
System.out.println("+++++++++++++++++++++");
}
AssertJUnit.assertEquals(count, rows.size());
}
按顺序遍历每行每列,当当前行匹配到第一个值符合搜索的字符时,该行剩下的列不再去匹配,跳到下一行,同时count+1(用来验证搜索到的总条目)
运行时出错了:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
百度了也不明白是怎么回事,是以为分页问题吗,求大神指教,不胜感激 |
|