2014-02-11 71 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 != ""