使用 selenium2+phpunit 选择一个选项 [英] select a option with selenium2+phpunit
问题描述
我有一个看起来像这样的选择元素,现在我想打开它并选择值为 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屋!