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.

  • 3
    In buttonText locator, you give the text of button, not the id. Try using by.buttonText('Login') – demouser123 Jan 24 '18 at 12:52
1

Use the following cssSelector:

var loginBtn = element(by.css(button[type = 'submit']));
|improve this answer|||||
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']));

|improve this answer|||||
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"]')
|improve this answer|||||
  • Please edit your answer to explain why your code would be better than the other answers. – Kate Paulk Jul 30 '18 at 11:48
  • @Kate, edited the answer, hope this helps. – Vishal Aggarwal Jul 30 '18 at 12:13
-1

You can use this

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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