2013-06-18 34 views
5

Tôi có một yếu tố lựa chọn mà trông như thế này, bây giờ tôi muốn mở nó lên và chọn tùy chọn với giá trị t3, vì vậy tôi đã thử nó như thế này:chọn một tùy chọn với selenium2 + phpunit

<select id="selectMenu"> 
<option value="">&nbsp;</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(); 

Bây giờ điều này mở menu nhưng nó không chọn thẻ tùy chọn, tôi nghĩ sử dụng select() thay vì click() nhưng select() chưa được hỗ trợ, hoặc ít nhất đó là thông báo tôi nhận được khi tôi cố gắng sử dụng phương thức. Tôi chạy phần mở rộng sau đây PHPUnit_Extensions_Selenium2TestCase.

Trả lời

12

nó tương đối đơn giản.

$this->select($this->byId('selectMenu'))->selectOptionByValue('t3'); 

điều này nên chọn tùy chọn của hộp chọn dựa trên giá trị. Sử dụng PHPUnit Selenium 2 v1.3.3

0

$ this-> byId ('selectMenu') -> selectOptionByValue ('t3');

2

tôi thấy tôi cần phải chuyển đổi các PHPUnit_Extensions_Selenium2TestCase_Element đến một PHPUnit_Extensions_Selenium2TestCase_Element_Select:

PHPUnit_Extensions_Selenium2TestCase_Element_Select::fromElement($this->byId('selectMenu'))->selectOptionByValue('t3'); 

Cũng thấy điều này other question

-1

Bạn có thể thử với

$this->select('css=#selectMenu','test 1'); 
0

Để chọn sử dụng giá trị sử dụng

 $this->select($this->byName())->selectOptionByValue($value); 

Để chọn sử dụng nhãn sử dụng

 $this->select($this->byName())->selectOptionByLabel($label); 
Các vấn đề liên quan