2015-10-30 102 views
0

我想要使用元素來獲取元素數組,但它不起作用。Webdriverio - 元素不起作用

任何人都可以幫助我呢?十分感謝。

這裏是我的代碼:

<select name="test" id="select"> 
<option value="1">1</option> 
<option value="2">2</option> 
<option value="3">3</option> 
</select> 

現在我試圖讓所有的選項元素:

client.url('www.somesite.com') 
    .elements('#select>option').then(function(res){ 
     console.log(res.length); 
    }) 

但我得到 '未定義' 對於 'res.length' 的結果。

如果我使用gettext然後我就可以得到正確的結果:

client.url('www.somesite.com') 
    .getText('#select>option').then(function(res){ 
     console.log(res.length); 
    }) 

回答

0

您需要訪問value屬性。

console.log(res.value.length); 
+0

非常感謝。有用! – andreas