Sree
Sree

Reputation: 31

how to get the already selected value of dropdown protractor

I have a select tag with some options under it . I select one value out of those along with other field values and move to next page. Once I return to previous page I want to check whether the dropdown value is same as that I selected. How can I get the already selected value using protractor. Can someone please help.

Upvotes: 0

Views: 5588

Answers (4)

sarath
sarath

Reputation: 1

The following code helps me to resolve the issue,now the variable contains the value of the dropdown selected

var dropdownval=element(by.xpath("XpathOfDropdown")).element(by.css('option:checked')).getText();
console.log(dropdownval);

Upvotes: 0

Sarath
Sarath

Reputation: 1

var dropdownval=element(by.xpath/css("Xpathofdropdown/cssofdropdown")).element(by.css('option:checked')).getText();    
console.log(dropdownval);

Upvotes: 0

toxicBurn
toxicBurn

Reputation: 127

Following @Grasshopper's comment, I read this, and the following worked for me:

expect(element(by.xxxxxx('xxxxxxx')).$('option:checked').getText()).toEqual('xxxxxx')

Upvotes: 3

Mezo Istvan
Mezo Istvan

Reputation: 2782

First select the input, then select the option using css, with the option:selected tag:

var selected = element(by.css('#ID_OF_THE_SELECT option:selected'))

Upvotes: -1

Related Questions