0

This is in Perl if it matters. I have several lists of links that collapse and expand. I know how many there are from using

get_xpath_count('//li/a')

The problem is I need to get a list of the names of these actual links. I've tried using xpath, but haven't found much luck, and was hoping CSS selectors would be able to help. I've tried using

get_text('css=li a:nth-child('.$i.')'

which prints out a [-] icon next to a link, the very top link in the list, and then an out of range error. I'm not familiar was CSS selectors at all, so any help would be great. If I left out important info, please let me know,

0

1 Answer 1

2

Try this (in pseudo-code, because I avoid Perl like the plague):

list linkNames;
count = selenium.get_xpath_count('//li/a');
for (i = 1; i <= count; i++) {
   list.append(selenium.get_text('xpath=(//li/a)[' + i +']');
}

Note:

  • XPath expressions count from 1 to n, not 0 to n-1 like most C-derived languages.
  • The XPath form for selecting the i'th match of a pattern is (pattern)[i], not pattern[i].
  • Selenium doesn't assume the (pattern)[i] locator is an XPath, so you need say so by starting it with xpath=.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.