使用selenium2 + phpunit选择一个选项 [英] select a option with selenium2+phpunit
问题描述
我有一个看起来像这样的select元素,现在我想将其打开并选择值为t3的选项,所以我尝试了如下操作:
I got a select element that look like this, now I want to open it up and select the option with value t3, so I tried it like this:
<select id="selectMenu">
<option value=""> </option>
<option value="t1">test 1</option>
<option value="t2">test 2</option>
<option value="t3">test 3</option>
<option value="t4">test 4</option>
<option value="t5">test 5</option>
<option value="t6">test 6</option>
</select>
$this->byId('selectMenu')->click();
sleep(1);
$type = $this->elements($this->using('css selector')->value(option[value="t3"]'));
$type[0]->click();
现在这将打开菜单,但是它没有选择选项标签,我想到了使用select()而不是click(),但还不支持select(),或者至少是我尝试获取的消息使用方法.我运行以下扩展PHPUnit_Extensions_Selenium2TestCase.
Now this opens the menu but it does not select the option tag, I thought of using the select() instead of click() but select() is not supported yet, or atleast that's the message i get when I try to use the method. I run the following extension PHPUnit_Extensions_Selenium2TestCase.
推荐答案
它相对简单.
$this->select($this->byId('selectMenu'))->selectOptionByValue('t3');
这应基于值选择框的选项.使用PHPUnit Selenium 2 v1.3.3
this should select the selectbox's option based on value. Using PHPUnit Selenium 2 v1.3.3
这篇关于使用selenium2 + phpunit选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!