1

I want a selenium RC java test script that prints all the links in a page which contains show/id.

I tried this

int servicecount= selenium.getXpathCount("xpath=//a[contains(@href,'show/id')]").intValue();
for(int servicecnt=1;servicecnt<=servicecount;servicecnt++)
{
  String some_container=selenium.getText("xpath= //a[contains(@href,'show/id')["+servicecnt+"]");
  System.out.println(some_container);
}

This doesn't work. Please suggest solutions.

4

1 回答 1

1

正如规范中所说,

注意:位置路径与位置路径//para[1]的含义不同/descendant::para[1]。后者选择第一个后代para元素;前者选择作为其父母para 的第一个孩子的所有后代元素。para

这意味着您需要使用后一种方法:

selenium.getText("xpath=/descendant::input[contains(@href,'show/id')]["+servicecnt+"]");
于 2013-09-05T13:11:51.380 回答