Tutorial :XPath loop with Selenium and perl


I'm trying to extract all name values in input fields using selenium and perl. Part of the value, enough to identify it, is known, the rest is unknown:

This xpath works in finding all relevant matches:


So, in perl:

my $xpath = qq(//tr/td//input[contains(\@name,'partofname')]);  my $count = $sel->get_xpath_count($xpath);  

Fine, $count gives a suitable count of matches.

However, how to extract the value of the @name attribute for each individual matches?

I understand the principle is to construct a loop:

foreach my $row (1 .. $count) {  #extract here  };  

However, I can't seem to construct an xpath expression which will work to find each $row that the expression matched. So I think it's the correct xpath expression to get each individual match that I need help with.

Any pointers appreciated


Try //tr/td/descendant::input[contains(@name,'partofname')][1]

Replace 1 with your counter. If that doesn't could you add some HTML to your question so I can perhaps suggest a better XPath?

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »