1

I am trying to verify that correct option is selected from selectbox using protractor.

This is how I pick value from selectbox:

element(by.id('form-mileage-unit')).click().then(function() {
    element(by.cssContainingText('option', browser.params.lengthUnit)).click();         
});;

So base on this I write code below:

it('Verify paint color', function() {       
    element(by.id('form-mileage-unit')).click().then(function() {
        element(by.cssContainingText('option', browser.params.lengthUnit).getAttribute("value")).toEqual(browser.params.lengthUnit);            
    });;
});     

Unfortunately I am getting error:

TypeError: Object by.cssContainingText("option", "Motohodin") has no method 'getText'

Can someone advise me with this?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Andurit
  • 5,612
  • 14
  • 69
  • 121

1 Answers1

1

You are closing the parenthesis in the wrong place and there is no expect(). Replace:

element(by.cssContainingText('option', browser.params.lengthUnit).getAttribute("value")).toEqual(browser.params.lengthUnit);

with:

var option = element(by.cssContainingText('option', browser.params.lengthUnit));
expect(option.getAttribute("value")).toEqual(browser.params.lengthUnit);

If you are dealing with select->option constructions a lot, consider using an abstraction over it that would make your tests cleaner and more readable, see:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Hi Alecxe, your advise is really clever, finaly had to fix it with getText instead of attribute (becuase it retun just number 2) , but you lead me for correct answer as always. I will check Select->option possibilitys as well :) – Andurit Jun 12 '15 at 14:12