使用webdriver.js,如何获得< select>?的所选选项 [英] With webdriver.js, how to get the selected option of a <select>?

查看:90
本文介绍了使用webdriver.js,如何获得< select>?的所选选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java和C#的答案很多,但我在javascript中找不到如何做到这一点。似乎API是不同的......

Plenty of answers for java and C#, but I can't find how to do it in javascript. Seems the API are different...

推荐答案

是的,这是可能的。假设我们有以下选择元素:

yeah it is possible. Lets say we have the following select element:

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

您可以使用getValue获取当前选定的选项,并可以使用单击更改选择。这是一个简单的例子:

You get the current selected option by using getValue and you can change the selection by using click. Here is an simple example:

var webdriverjs = require('webdriverjs'),
    client      = webdriverjs.remote({desiredCapabilities:{browserName:'phantomjs'}}).init();

client
    .url('http://localhost:8080')
    .getValue('#select',function(err,val){
        console.log(val); // will output "1"
    })
    .click('//*[@id="select"]/option[3]')
    .getValue('#select',function(err,val){
        console.log(val); // will output "3"
    })
    .end();

希望有所帮助。

欢呼

这篇关于使用webdriver.js,如何获得&lt; select&gt;?的所选选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆