计算下拉菜单中的选项数量,然后在PHPUnit中选择

时间:2012-09-26 17:10:55

标签: selenium phpunit

这是代码

<select id="filter_step_id" onchange="master.updateFilter();" name="filter_step_id">
    <option value="">Step</option>
    <option value="setup">company</option>
    <option value="cofounder">co-founder</option>
    <option value="project">project</option>
    <option value="idea">idea</option>
    <option value="product">product</option>
    <option value="sell">Sell</option>
    <option value="money">money</option>
    <option value="talent">talent</option>

如何计算此下拉菜单中的选项数量并获取文本并将它们放入数组(而不是值)?

这是我得到的

$numOptions = $this->storeXpathCount("//select[contains(@id,'filter_step_id')]//option[contains(@value, '')]");
for($i = 0; $i <= $numOptions; $i ++) {
    (code to select one option and checking if the text is present from using the filter)
}

1 个答案:

答案 0 :(得分:0)

$stepCount = $this->getXpathCount("//select[contains(@id,'filter_step_id')]//option[contains(@value, '')]");
    for($i = 2; $i <= $stepCount; $i ++) {
        $stepOptions = $this->getText("xpath=(//select[contains(@id,'filter_step_id')]//option[contains(@value, '')])[$i]");
        $this->select("id=filter_step_id", "label=$stepOptions");
        sleep(2);
        $this->assertTextPresent("$stepOptions");
    }