2016-12-01 60 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