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:
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:
$xpath = qq(//table[\@id='table_12345']/tbody/tr[4]/td[7])
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.
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.