Shari
Shari

Reputation: 123

Selenium RC- Print all links that contains a text

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.

Upvotes: 1

Views: 883

Answers (1)

Petr Janeček
Petr Janeček

Reputation: 38424

As said in the spec,

NOTE: The location path //para[1] does not mean the same as the location path /descendant::para[1]. The latter selects the first descendant para element; the former selects all descendant para elements that are the first para children of their parents.

That means that you need to use the latter approach:

selenium.getText("xpath=/descendant::input[contains(@href,'show/id')]["+servicecnt+"]");

Upvotes: 1

Related Questions