Rational Functional Tester, how to dynamically identify links in an HTML table?

StackOverflow https://stackoverflow.com/questions/10807417

  •  11-06-2021
  •  | 
  •  

문제

I have HTML that looks something like this:

<table summary="History of xxxxxx"><thead><tr><th>Date Started</th><th>Date Updated</th><th>Yyyyyyyy</th><th>Summary Report</th>  
<th>Full Report</th></tr></thead><tbody><tr class="odd"><td>05/29/2012</td><td>05/29/2012</td>  
<td><a href="/xxxxx/yyyyy/traversal/e3230f12-dea6-4fd9-b4ed-dd60deb65aa3">Complete  </a>  
<a href="/xxxxx/yyyyy/delete">Delete</a></td><td/><td/></tr><tr class="even"><td>05/29/2012</td>  
<td>05/29/2012</td><td/><td><a href="/xxxxx/summaryreport/view/280e30fe-f7dc-4099-b83e-28e02d64f68f">View</a>  
<a href="/xxxxx/summaryreport/save/280e30fe-f7dc-4099-b83e-28e02d64f68f">Save</a>  
<a href="/xxxxx/summaryreport/print/280e30fe-f7dc-4099-b83e-28e02d64f68f">Print</a></td><td>  
<a href="/xxxxx/fullreport/view/280e30fe-f7dc-4099-b83e-28e02d64f68f">View</a>  
<a href="/xxxxx/fullreport/save/280e30fe-f7dc-4099-b83e-28e02d64f68f">Save</a>  
<a href="/xxxxx/fullreport/print/280e30fe-f7dc-4099-b83e-28e02d64f68f">Print</a></td></tr></tbody></table>

I can print the content of the table using the following script fragment:

ITestDataTable kontents = (ITestDataTable) table_dateStartedDateUpdatedAs().getTestData("contentswithchildren");

System.out.println (table_dateStartedDateUpdatedAs().getTestDataTypes());

System.out.println ("Total Rows in table : " + kontents.getRowCount());
System.out.println ("Total Cols in table : " + kontents.getColumnCount());

for (int row=0; row < kontents.getRowCount();++row)
{
for (int col=0; col < kontents.getColumnCount();++col)
{
    System.out.println("contents("+row+","+col+")=\""+kontents.getCell(row,col)+"\"");
}
}

But how can I get the hyperlinks into their own variables? The three hyperlinks, View Save Print, are all in one cell.

--Thank you,

--Mike Jr.

도움이 되었습니까?

해결책

Use the find() function.

Take a look at the searching for test objects article in the online RFT help.

Sample code for your table would look something like the following:

TestObject[] foundSaveLinks = table_dateStartedDateUpdatedAs().find(atDescendant(".tag", "A", ".text", "Save"));
GuiTestObject saveLink = (GuiTestObject)foundSaveLinks[0];
saveLink.Click();

You can make this more complex, for example if you need to limit the search/find to a specific table cell. My sample above will find all of the "Save" links that are descendants of the table.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top