单击selenium中的动态链接

时间:2011-01-14 12:44:59

标签: vb.net visual-studio-2010 xpath selenium

我需要点击动态生成id的表中的链接。我想根据同一行中某些其他列中的文本单击链接。尝试以下代码但不成功

selenium.GetValue( “//表[@ ID =表格ID] / tbody的/ TR [TD /一个/文本()= '测试']”)

还尝试使用以下代码 Selenium.click(“xpath = id(TableID)/ tbody / tr [td / text()='Testing'] //输入[@ value ='删除']”)

尝试了以下代码,但仅通过指定静态行ID

起作用
 Dim NumOfRows As Integer = selenium.GetXpathCount("//table[@id='up']/tbody/tr")
        'Dim index As Integer
        Dim ReturnValue As Integer
        Dim IsFound As Boolean = False
        Console.WriteLine(NumOfRows)

        For i As Integer = 1 To NumOfRows
            Dim strColumnText As String = selenium.GetText("//table[@id='up']/tbody/tr[i]/td[1]")
            'selenium.WaitForCondition(strt, 100000)
            If (strColumnText = pord) Then
                ReturnValue = i
                IsFound = True
                Exit For
            End If
        Next

如果我指定了确切的行,它将找到该元素但不在循环中工作。请帮忙

1 个答案:

答案 0 :(得分:1)

如果值在表中,您应该使用

selenium.getTable("tableName.0.1");

其中0是行,1是列(基于0的索引)

如果成功,getTable将返回一个字符串:“OK,value”所以你需要删除OK,part。

<强>更新 添加到user-extensions.js

    Selenium.prototype.getTableRows = function(locator) {
  /**
   * Gets the number of rows in a table.
   *
   * @param locator element locator for table
   * @return number of rows in the table, 0 if none
   */

    var table = this.browserbot.findElement(locator);
    return table.rows.length.toString();
};

Selenium RC

// Table Name in inputParams

    String[] inputParams = { "tblTryggHuvudlantagare", };

                String y = proc.doCommand("getTableRows", inputParams);
                String tmpString = y.replace("OK,", "");

                // Rows minus headings


    int tableRows = Integer.valueOf(tmpString).intValue() - 1;

        for (int i = 1; i < tableRows; i++) {
    // Your logic here to see if you reached the right row and then click button on same row..
                    }