Webdriverio - 元素不起作用

时间:2015-10-30 21:12:23

标签: webdriver-io

我正在尝试使用Elements来获取元素数组,但它在这里不起作用。

任何人都可以帮助我吗?非常感谢。

这是我的代码:

<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);
    })

1 个答案:

答案 0 :(得分:2)

您需要访问value属性。

console.log(res.value.length);
相关问题