Using selenium CSS selector for multiple things
This is in Perl if it matters. I have several lists of links that collapse and expand. I开发者_StackOverflow 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,
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]
, notpattern[i]
. - Selenium doesn't assume the
(pattern)[i]
locator is an XPath, so you need say so by starting it withxpath=
.
精彩评论