3
votes

I am using Protractor for end to end testing in Angular application. I am trying to click on option in select box, but i have folowing error Element is not currently visible and may not be manipulated.

I have this part of html:

<select class="form-control" ng-required="true" ng-model="selectedAction.begStatus"
        ng-options="obj as obj.name for obj in allBegStatuses">
</select>

And I have this line of code in Protractor test:

element(by.xpath('//select/option[text()="Draft"]')).click();

I want to click on option with value "Draft". Do you know maybe what is the problem?

5
why don't you want to select element by model?Stepan Suvorov
You should use the options locator. EG: element.all(by.options('obj as obj.name for obj in allBegStatuses')); This link can show you how to apply a filter in the option list.flaviomeira10

5 Answers

4
votes
var option = element.all(by.options('obj as obj.name for obj in allBegStatuses'));
var selectOption = option.get(1);
selectOption.click();
1
votes

I made a function for select(by id) and clicks an option by text compare.

this.selectOption = function (selector, item) {
        var selectList, desiredOption;
        selectList = element(by.id(selector));
        selectList.all(protractor.By.tagName('option'))
            .then(function (options) {
                options.some(function (option) {
                    option.getText().then(function (text) {
                        if (item.toLowerCase() === text.toLowerCase()) {
                            desiredOption = option;
                            return true;
                        }
                        return true;
                    });
                });
            })
            .then(function () {
                if (desiredOption) {
                    desiredOption.click();
                }
            });
    };

hopefully it works for you to

1
votes

How about this:

element(by.xpath('//*[@id="controlId"]/option[3]')).click();

This should select the value in the drop down.

Hope it helps.

0
votes

select by model:

element(by.select("selectedAction.begStatus"))
0
votes

This worked for me:

    function selectOptionByText (selectBox, optionText) {
        selectBox.element(by.cssContainingText('option', optionText)).click();
    }