2013-06-12 17 views
0

我試圖單擊表格中的複選框。我在表中搜索,當我發現在第2列適當的信息我想點擊複選框在該行單擊活動行第一列中的複選框

public WebDriver searchSelectStore(WebDriver dr1, String srchTable, String srchFor) { 
// Grab the table 
    WebElement table = dr1.findElement(By.id(srchTable)); 

    // Now get all the TR elements from the table 
    List<WebElement> allRows = table.findElements(By.tagName("tr")); 

    // And iterate over them, getting the cells 
    for (WebElement row : allRows) { 
     List<WebElement> cells = row.findElements(By.tagName("td")); 

    for (WebElement cell : cells) { 
     // 

     if(cell.getText().equals(srchFor)){ 


       System.out.println(row.getText()); 

        // here I need to click on the first column of that row 



      } 

     } 

回答

0

其實我重寫代碼一點點的第一列,因爲你說你總是檢查文本的第二個單元格,然後發現時,點擊第一個我會做這樣的事情:

List<WebElement> allRows = table.findElements(By.tagName("tr")); 
for (WebElement row : allRows) { 
    if (row.findElement(By.xpath("./td[2]").getText().equals(srchFor)){ 
     row.findElement(By.xpath("./td[1]").click(); 
    } 
} 
相關問題