【发布时间】:2016-06-02 17:05:46
【问题描述】:
我已经编写了一个代码来验证该行中是否存在给定的文本,但是我如何单击特定的单元格?请帮帮我。
下面是我为验证文本而编写的代码。
package com.Tables;
import java.util.List;
public class HandlingTables {
public static void main(String[] args) throws InterruptedException {
String s="";
System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.w3schools.com/html/html_tables.asp");
WebElement table = driver.findElement(By.className("w3-table-all"));
List<WebElement> allrows = table.findElements(By.tagName("tr"));
List<WebElement> allcols = table.findElements(By.tagName("td"));
System.out.println("Number of rows in the table "+allrows.size());
System.out.println("Number of columns in the table "+allcols.size());
for(WebElement row: allrows){
List<WebElement> Cells = row.findElements(By.tagName("td"));
for(WebElement Cell:Cells){
s = s.concat(Cell.getText());
}
}
System.out.println(s);
if(s.contains("Jackson")){
System.out.println("Jackson is present in the table");
}else{
System.out.println("Jackson is not available in the table");
}
Thread.sleep(10000);
driver.quit();
}
}
【问题讨论】:
-
我想点击表格中的特定单元格,因为表格中的单元格可能有需要输入的下拉菜单或文本字段。