硒测试

发布于 2024-08-31 13:04:44 字数 246 浏览 9 评论 0原文

我想使用 xpath 获取一堆 dom 对象并循环遍历它们以检查它们是否包含指定的文本,这在 Selenium IDE 或 rc 中可能吗? Perl 是我更喜欢的语言

XPath 会是这样的 xpath=//tbody[@class='table-data']/tr/td/div[@class='table-item']

这将返回表中的所有行项目,但我需要检查每个 div 是否包含指定的文本字符串。这对于硒来说可能吗?

此致

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独木成林 2024-09-07 13:04:44

WWW::Selenium 模块非常适合你的需要。

来自 对另一个问题的较早回答

它支持通过 xpath 元素、表 ID、文本(正则表达式匹配!)和 URL 访问元素...

您需要下载 Selenium
偏僻的
控制

并让它在后台运行
使模块正常工作。

需要注意的是,如果您的页面加载时间不可预测,这可能不是一个好的选择。

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.

栖迟 2024-09-07 13:04:44

如果您想要的只是 HTML 的 XPath 搜索,那么有许多模块可供选择< /a>,但是 Test::XPath 看起来是最好的。

  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' );

我的 XPath 可能有点偏差,但您明白了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文