当单元格包含更多字段时,我无法单击表格中的“复选框”

时间:2013-08-01 13:19:12

标签: java selenium-webdriver

此表中的问题复选框http://dl.dropboxusercontent.com/u/55228056/Locators.html 在复杂的表格下,您可以看到Access下的复选框,我想在Selenium中使用java检查这些复选框。

以下是我试过的代码..

我为Web表创建了一个类

public class Table 
{
public WebElement getCellEditor(int rowIdx,int colIdx,int editorIdx)
{
    try
    {
    List<WebElement> tablerows=_webTable.findElements(By.tagName("tr"));
    WebElement currentrow=tablerows.get(rowIdx-1);
    List<WebElement> tablecols=currentrow.findElements(By.tagName("td"));
    WebElement cell=tablecols.get(colIdx-1);
    WebElement cellEditor=cell.findElements(By.tagName("input")).get(editorIdx);

    return cellEditor;

    }catch(NoSuchElementException e)
    {

        throw new NoSuchElementException("Failed to get cell editor");
    }

    }

将其扩展到其他类。

public class TestWebTable 
{

public void printTable() throws InterruptedException
{
    try
    {
        Table table=new Table(driver.findElement(By.id("users")));
        WebElement cellEdit=table.getCellEditor(3,3 ,2);
        cellEdit.click();
        Thread.sleep(5000);
        /*WebElement cellEdit2=table.getCellEditor(3,3,4);
        cellEdit2.click();*/


    }catch(Error e)
    {
        verificationErrors.append(e.toString());
        System.out.println(verificationErrors.toString());
    }
}

如果我通过给(rowindex,columnindex,editorindex)提供(3,3,2)来检查复选框,则复选框将不会被选中。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,那么该表只有2行。所以行列表的索引应该是0和1.您正在尝试获取索引为2的行(rowIdx-1),这些行在tablerow列表中不存在。 您可以尝试在创建时打印每个列表的大小吗?