Clicking on a dynamic link in selenium
I need to click on link in a table whose id is generated dynamically. I want to click on a link based on a text in some other column in the same row. Tried the following code but unsuccessful
selenium.GetValue("//tabl开发者_JAVA百科e[@id=TableID]/tbody/tr[td/a/text()='Testing']")
Also trying with the following code Selenium.click("xpath=id(TableID)/tbody/tr[td/text()='Testing']//input [@value='Delete']")
Tried the following code but only works by specifying a static row 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
If I specify exact row it will find the element but not working in a loop. pls help
If the value are in a table you should use
selenium.getTable("tableName.0.1");
Where 0 is the row and 1 is for the column (0 based index both of them)
getTable will return an string if successful: "OK,value" so you need to strip out the OK, part.
Update Add to 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..
}
精彩评论