WWW::Mechanize::Firefox xpath on previous result

354 Views Asked by At

Can I execute a XPath query on previous result? I have this xpath:

my @objDivRes = $objBrow->xpath('//div[@id="result"]/ol/div/li', all => 1);

but when I execute xpath function on previous result

my @objLink = $objDivRes[0]->MozRepl::RemoteObject::Methods::xpath('//div/h3/a');

I got an error:

MozRepl::RemoteObject: TypeError: doc.evaluate is not a function at test.pl

Is there an example? Thank you

1

There are 1 best solutions below

0
On

Just use 'node' option to set up a subtree $mech->xpath( $query, %options )

Note dot in the beginning of the path, which means descendands of the context node

my @objDivRes = $objBrow->xpath('//div[@id="result"]/ol/div/li', all => 1);

my @objLink = $objBrow->xpath('.//div/h3/a', node => $objDivRes[0]);