Our dev has a submit button like this:

<button _ngcontent-c6="" class="btn btn-block btn-primary mt-lg" type="submit">Login</button>

I tried using:


but no luck with it.

Note: I'm new to protractor.

  • 3
    In buttonText locator, you give the text of button, not the id. Try using by.buttonText('Login') Jan 24, 2018 at 12:52
  • element(by.buttonText('Login')).click();
    – Jeeva
    May 22, 2020 at 12:24

4 Answers 4


Use the following cssSelector:

var loginBtn = element(by.css(button[type = 'submit']));
  • Shouldn't this be by.css("button[type = 'submit']") ?
    – rrauenza
    Jul 17, 2020 at 6:17

It seems there is mismatch. You are trying to use ID as text which is incorrect.

If you want to use by.buttonText then your code should be by.buttonText('Login')

Or you can also use css selector like element(by.css(button[type = 'submit']));


I prefer to use submit property in this scenario instead of button text as it is less fragile as it is less likely to be changed compared to text.

I would use precisely:

  • Please edit your answer to explain why your code would be better than the other answers.
    – Kate Paulk
    Jul 30, 2018 at 11:48
  • @Kate, edited the answer, hope this helps. Jul 30, 2018 at 12:13

You can use this


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.