Select an option in a dynamic select with codeception?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 18:35:18

问题


<select>
    <option value=''>-- Select an Option --</option>
    @foreach ($options as $option)
        <option value='{{ $option->value }}'>{{ $option->name }}</option>
    @endforeach
</select> 

Select the first dynamic option


回答1:


$option = $I->grabTextFrom('select option:nth-child(2)');
$I->selectOption("select", $option);
$I->click("Submit");



回答2:


I've run into the same issue quite often when starting out with Codeception. Using the recommended answer, I created a helper function in my AcceptanceTester class to make this a little easier.

public function selectFromDropdown($selector, $n)
{
    $option = $this->grabTextFrom($selector . ' option:nth-child(' . $n . ')');
    $this->selectOption($selector, $option);
}

Where $n is the position in the option list.

Then all you have to do is call it like this:

$I->selectFromDropdown('select', 1);

This has been working for me on pages that have several select's that load their option list based on the selected option of the previous select.




回答3:


sorry i do not have submit button, in my case i have to select the dropdown element and somehow need to tell the codeception to finish the selection.At the moment i can select but that select is not visible as i suppose the selection is not finished somehow.Below is my code to select the element.

$I->selectOption('//*[@class="ng-scope" and @ng-controller="dataIsland"]/*[local-  name()="select"]','partlycloudy');


来源:https://stackoverflow.com/questions/17413985/select-an-option-in-a-dynamic-select-with-codeception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!