Reputation: 31
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
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
Reputation: 1
var dropdownval=element(by.xpath/css("Xpathofdropdown/cssofdropdown")).element(by.css('option:checked')).getText();
console.log(dropdownval);
Upvotes: 0
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
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