Selenium Webdriver处理复选框及获取表格指定单元格的内容

来源:互联网 发布:linode vps建站 编辑:程序博客网 时间:2024/06/04 18:07

通过xpath定位处理

List<WebElement> checks = driver.findElements(By.xpath("//input[@type='checkbox']"));System.out.println(checks.size());  //获取页面上复选框个数for(int i =0;i<checks.size();i++){  //勾选所有复选框   checks.get(i).click();   if(checks.get(i).isSelected()){   //判断复选框是否被勾选      System.out.println((i+1)+"is Selected");   }            }

获取表格指定单元格的内容

/*** 获取表格指定单元格的文本内容* @param row 行号-1;column 列号* @param i  第几个表格* @param location 元素位置* @return 返回获取到的页面元素的文本*/  public  String table(int i , int row , int column /*, String id*/){  String text = null;  row=row+1;  String loction = "//table["+i+"]/tbody/tr["+row+"]/td["+column+"]";  //第i个表格  //String loction="//*[@id='"+id+"']/tbody/tr["+row+"]/td["+column+"]";  通过id定位  WebElement table=driver.findElement(By.xpath(loction));   text=table.getText();  return text;}    System.out.println(table(1,1,2)); //第1个表格第2行第2列
1 0
原创粉丝点击