Protractor clear dropdown menu

When doing transported tags, I would like to remove the dropdown. I know how to select a specific option from the dropdown. How can you clean it up?

The dropdown is part of the form. The parameter values ​​for the dropdown are loaded with an ajax call. So, the choice looks something like this.

<select>
  <option>First Value</option>
  <option>Second Value</option>
<select>

      

Now that the form is loaded, no value is selected. But once a value has been selected, it cannot be cleared (even manually) as it is a required field. An alternate value can be selected from the drop-down menu.

However, I would like to make a second test that checks if the value of this field is empty (no selection). To do this, I need to clear the dropdown. Does the protractor provide a way?

Let's say I somehow can't change the order of the tests.

I am currently reloading the whole form to clear the dropdown.

+3


source to share


1 answer


If the dropdown menu cannot be entered, the only way to clear the dropdown with Protractor is to be able to in the dropdown, which acts as the default selection, before the user selects First Value or Second Value. It can be empty as well, for example you want

Something like that:

<select>
    <option></option>
    <option>First Value</option>
    <option>Second Value</option>
</select>

      



And then select the first option with

element.all(by.tagName('option')).get(0).click();

      

This will give you the desired effect. Let me know if this helps!

+1


source







All Articles