1

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:

element(by.buttonText('#submit')); 

but no luck with it.

Note: I'm new to protractor.

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

4 Answers 4

1

Use the following cssSelector:

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

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']));

0

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:

$('button[type="submit"]')
2
  • Please edit your answer to explain why your code would be better than the other answers.
    – Kate Paulk
    Commented Jul 30, 2018 at 11:48
  • @Kate, edited the answer, hope this helps. Commented Jul 30, 2018 at 12:13
-1

You can use this

element(by.xpath('//button[contains(text(),"Login")]')).click();

Your Answer

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

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