开发者

Selenium Testing

I w开发者_如何学JAVAant 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜