Pindakaas
Pindakaas

Reputation: 4439

protractor no element found using locator by cssselector?

Getting my head around protractor... How can I access a button element on an angularjs page that looks like this:

<button class="button primary">Save</button>

Using this in my test:

element(by.css('button primary')).click();

Getting an error:

NoSuchElementError: No element found using locator: By.cssSelector("button primary")

How can I fix this?

Upvotes: 6

Views: 12966

Answers (3)

nagrom97
nagrom97

Reputation: 514

There are a few selectors to use, depending on the state of the application. Personally, as we speak I am developing a site that has lots of buttons styled with the same class (for styling, fonts etc) and it can get quite annoying when there might be more than one button with the same class on one page so you might want to give it a special, unique id or select using button text, which is easiest in my opinion:

element(by.buttonText('Save')).click();

But it is a matter of preference , Only sharing my opinion. Have a good day! :)

Upvotes: 2

Yogi
Yogi

Reputation: 408

element(by.buttonText('Save')).click();

Upvotes: 1

Leo Gallucci
Leo Gallucci

Reputation: 16722

element(by.css('button.button.primary')).click();

Upvotes: 7

Related Questions