如何使用 Capybara 获取元素中的 HTML? [英] How do I get the HTML in an element using Capybara?
本文介绍了如何使用 Capybara 获取元素中的 HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个黄瓜测试,我想在其中获取元素中的 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
这篇关于如何使用 Capybara 获取元素中的 HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文