1

I want to get a bunch of dom-objects with xpath and loop through those to check if they contains a specified text, is this possible in the Selenium IDE or rc? Perl is my prefered language

XPath would be something like xpath=//tbody[@class='table-data']/tr/td/div[@class='table-item']

This would return all row items in the table, but i need to check each div if contains a specified text string. Is this possible with Selenium?

Best regards

1
  • 1
    WWW::Selenium is the obvious part (or Test::WWW::Selenium). Could someone answer more explicitly the "test that multiple divs matching an xpath all contain specified text"? Or at least show a hint of how to do the "multiple" or "contain specified text" parts? Commented May 5, 2010 at 17:00

2 Answers 2

1

The WWW::Selenium module is perfect for your need.

From an older answer to another question:

It supports access to elements via xpath elements, table IDs, text (regex-matching!) and URLs...

You'll need to download the Selenium Remote Control and have it running in the background for the module to work.

A caveat is that it may not be a good option if your page load times are unpredictable.

Sign up to request clarification or add additional context in comments.

Comments

0

If all you want is XPath searching of HTML there's a number of modules to choose from, but Test::XPath looks the best of the lot.

  use Test::XPath;

  my $html = ...get it however...

  # Create a Test::XPath object from your HTML
  my $tx = Test::XPath->new( xml => $html, is_html => 1 );

  # Test for the existence of your table rows.
  $tx->ok( q{//tbody[@class='table-data']/tr/td/div[@class='table-item']}, sub {
      # Run more tests on each node returned by the above xpath expression
      $_->like( './text()', qr/specified text/, "row contains the right text" );
  }, 'found table rows' );

My XPath may be a little off, but you get the idea.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.