2011-01-14 160 views
0

我需要点击一个表中的链接,其ID是动态生成的。我想单击基于同一行其他列中文本的链接。尝试下面的代码,但不成功点击硒动态链接

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

还与试图下面的代码: Selenium.click(“xpath = id(TableID)/ tbody/tr [td/text()='Testing'] //输入[@值=代码,但只能通过指定静态行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 

如果我指定精确的行会找到它的元素,但在厕所不能正常工作页。请帮助

+0

对于作为答案,你需要提供输入样本的XPath表达式。 – 2011-01-17 15:44:16

回答

1

如果该值是在一个表,你应该使用

selenium.getTable("tableName.0.1"); 

其中0是行,1是列(0基于指数两者)

getTable将返回字符串如果成功:“确定,值”,因此您需要删除OK,部分。

更新 添加到用户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(); 
}; 

硒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.. 
        } 
+0

这里您指定了精确的行和列,但我必须根据值'testing'选择一行,然后单击另一列中同一行上的删除按钮。任何想法如何做到这一点.. – sam 2011-01-14 15:10:17