Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (11.4k points)

I am new to Selenium Remote Control (RC). My requirement is that I have to search Selenium from Google and find out how many results from www.seleniumhq.org are displayed in the first 10 results.

I tried:

int count = selenium.getXpathCount(
  "xpath=//a[contains(@href,'www.seleniumhq.org')]"
).intValue();


But it gives the wrong count, since its counted links below www.seleniumhq.org; e.g download, selenium documentation, etc.

Correct count should be 2 since there is only 2 links which contains www.seleniumhq.org:

  • www.seleniumhq.org
  • www.seleniumhq.org/download/‎


Please suggest the solution.

1 Answer

0 votes
by (32.3k points)

You can try the approach given below:

 int count= selenium.getXpathCount("xpath=//a[@onmousedown and @href and @data-cthref and contains(@href,'www.seleniumhq.org')]").intValue();

 Here I am checking if the attributes are present and then I am providing the count.

Hope this helps!

Browse Categories

...