redrose123 has asked for the wisdom of the Perl Monks concerning the following question:

I have just started using Selenium with Perl today and would like to know a few things. 1) How can I save the value of some text from a web page? 2) Can I use reg exp comparing text? Spent a few hours trying but have got no where. Any help greatly appreciated. Thanks,

Replies are listed 'Best First'.
Re: selenium: saving text and reg exp
by planetscape (Chancellor) on Dec 18, 2009 at 15:07 UTC
Re: selenium: saving text and reg exp
by Limbic~Region (Chancellor) on Dec 18, 2009 at 15:58 UTC
    redrose123,
    With more information, I could be more specific. WWW::Selenium provides a myriad of methods that may be applicable to your situation.
    • get_title()
    • get_body_text()
    • $sel->get_html_source() - which you can use your favorite HTML parser with
    • $sel->is_text_present($pattern) - which takes a regular expression

    Cheers - L~R

Re: selenium: saving text and reg exp
by ww (Archbishop) on Dec 18, 2009 at 14:54 UTC
Re: selenium: saving text and reg exp
by spq (Friar) on Dec 18, 2009 at 16:04 UTC

    There is a selenium command for almost anything you want to do in testing a web page. For example, using the IDE you will find a number of store commands, such as storeText. I have found that frequently the fastest way to find out how to do something with a selenium test in Perl (my experience with Selenium is almost all front end through the IDE) is to add an appropriate command in the IDE and then export to Perl to see the syntax used.

    So, for storeText I found the example boiled down to:

    my $text = $sel->get_text("//xpath");