开发者

XPath loop with Selenium and perl

开发者 https://www.devze.com 2023-01-06 01:50 出处:网络
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:

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:

//tr/td//input[contains(@name,'partofname')]

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 m开发者_运维知识库atches.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消