2014-02-11 68 views
0

我需要一种方法来检查一个元素是否有孩子。水豚/ Poltergeist:检查div有小孩

<div class="purchaseRoMPixels"> 
     <img style="display:none" src="//api.com;value=20"> 
     <noscript>&lt;img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com" /&gt;</noscript> 
    </div> 

我尝试以下,但他们不工作

find(".purchaseRomPixels").children.length.should > 0 

这也并不正确测试什么,我想测试

find(".purchaseRoMPixels").text.should == "" 

这将始终返回true,因为有该div中没有​​文字。但我希望它只有在div中存在这些元素时才会返回true。

回答

0

尝试:

expect(find(:css, '.purchaseRoMPixels').text).to_not be_empty 

我觉得你在这行你的例子搞砸:

find(".purchaseRoMPixels").text.should == "" 

,并想用一个不等于而非等于运营商,我的意思是:

find(".purchaseRoMPixels").text.should != ""