2016-12-01 39 views
0

我想从selenium 2的下拉菜单中选择一个项目,并结合phpunit。我使用的类是PHPUnit_Extensions_Selenium2TestCase。我知道在硒1它是:select index selenium 2 php

$this->select("id=dt-general-input", "index=3"); 

但如何将此转换为硒2?要选择你要做的元素:

$ this-> select($ this-> byId(“dt-general-input”));

但我该如何选择第三个索引?此选择没有(文本)标记的选项。所以我不能使用$this->select($this->byId("dt-general-input"))->selectOptionByValue(3);

回答

1

您可以使用

$this->select($this->byId("dt-general-input"))->selectOptionByLabel('Label'); 

或者

$this->select($this->byId("dt-general-input"))->selectOptionByValue('the option value'); 

对于

<option value="the option value">Label</option> 

对于第三个指标,你会使用2不3还顺便一提。

如果你的选项值都是空的,你需要在列表中的第三个,你就做

// Returns an array of elements 
$allOptions = $this->select($this->byId("dt-general-input"))->options(); 
$thirdOpton = $allOptions[2]; 
+0

感谢您的指针。方法options()对于Selenium 2来说似乎不可用。但是我可以使用selectOptionLabels()和selectOptionValues()来代替。 – user3379159