【问题标题】:Clicking the Checkbox in the first column of the active row单击活动行第一列中的复选框
【发布时间】:2013-06-08 13:54:21
【问题描述】:

我正在尝试单击表格中的复选框。我搜索表格,当我在第二列中找到正确的信息时,我想单击该行第一列中的复选框

    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



             }

        }

【问题讨论】:

    标签: java selenium select checkbox html-table


    【解决方案1】:

    我实际上会稍微重写你的代码,因为你说你总是检查第二个单元格中的文本,然后在找到时点击第一个单元格,我会这样做:

    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();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 2015-05-26
      • 1970-01-01
      相关资源
      最近更新 更多