CColin has asked for the wisdom of the Perl Monks concerning the following question:
Hi - have started using Selenium with Perl - trying to find out how to locate text then turn it into the sort of XPath style link that Selenium wants.
So, I can get to the page I want, which has a bunch of dynamic text with loosely associated links (so not hyperlinks, so the ("link=$whatever") syntax for the click method is no use, in a table I want to click.
Anyway, since the starting point is static, I can get to the page of links I want. I discovered this method which looks like it may be useful from this point:
So I can pull HTML, and therefore locate the text in the html - but how to turn this into the Xpath style links that Selenium expects?
By XPath style links I am referring to the output that you get from using the Selenium IDE - interacting with the website I can see that this produces clickable output like this:
Using HTML::Treebuilder::XPath looked like it might be the right thing to do, but it seems you already have to know how to query your document using XPath. Seems to me that if I knew exactly how to get the XPath syntax to click the link I wouldn't need it in the first place... all I have to go on is the text to start with.
Thanks for any pointers.
Anyway, since the starting point is static, I can get to the page of links I want. I discovered this method which looks like it may be useful from this point:
my $html = $sel->get_html_source();
So I can pull HTML, and therefore locate the text in the html - but how to turn this into the Xpath style links that Selenium expects?
By XPath style links I am referring to the output that you get from using the Selenium IDE - interacting with the website I can see that this produces clickable output like this:
If I can get to the point of working out that the HTML can be converted to this by parsing said HTML, then all will be fine, as using $sel->click($xpath) works fine.$xpath = qq(//table[\@id='table_12345']/tbody/tr[4]/td[7])
Using HTML::Treebuilder::XPath looked like it might be the right thing to do, but it seems you already have to know how to query your document using XPath. Seems to me that if I knew exactly how to get the XPath syntax to click the link I wouldn't need it in the first place... all I have to go on is the text to start with.
Thanks for any pointers.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Links with Selenium in XPath
by Fletch (Bishop) on Jun 24, 2010 at 18:50 UTC | |
by CColin (Scribe) on Jun 29, 2010 at 08:20 UTC |
Back to
Seekers of Perl Wisdom