如何使用 Capybara 获取元素中的 HTML?如何使用、元素、Capybara、HTML

由网友(生命是一场旅途)分享简介:我正在编写一个黄瓜测试,我想在其中获取元素中的 HTML.I’m writing a cucumber test where I want to get the HTML in an element.例如:within 'table' do# this worksfind('//tr[2]//td[7]').te...

我正在编写一个黄瓜测试,我想在其中获取元素中的 HTML.

I’m writing a cucumber test where I want to get the HTML in an element.

例如:

within 'table' do
  # this works
  find('//tr[2]//td[7]').text.should == "these are the comments" 

  # I want something like this (there is no "html" method)
  find('//tr[2]//td[7]').html.should == "these are the <b>comments</b>" 
end

有人知道怎么做吗?

推荐答案

可以调用HTML DOM innerHTML属性:

You can call HTML DOM innerHTML Property:

find('//tr[2]//td[7]')['innerHTML']

应该适用于任何浏览器或驱动程序.您可以在 w3schools

Should work for any browser or driver. You can check all available properties on w3schools

阅读全文

相关推荐

最新文章