protractor icon indicating copy to clipboard operation
protractor copied to clipboard

How to click a ng-Submit button in protractor

Open DivsBellur opened this issue 12 years ago • 2 comments

Hello, I am new to protractor and help will me very much appreciated. How do I click ng-Submit button in protractor?

Here is the piece of jsp code I am trying to test by submitting the form by clicking :

. . .

Here is my piece of protractor test code to click this button.

ptor.findElement(protractor.By.id('StartJobButton').click().then(function(){ ptor.waitForAngular(); expect(ptor.currentUrl()).toContain('#blah'); }));

And below is the error I get when I run my test:

 TypeError: Object By.id("StartJobButton") has no method 'click'

Could someone let me know how to click a button in protractor implemented using ng-submit?

Thanks, Divya

DivsBellur avatar Dec 13 '13 18:12 DivsBellur

Youre calling click on By.id("StartJobButton"), not the WebElement.

I think you need to do something like:

var elem = ptor.findElement(protractor.By.id('StartJobButton'));
elem.click().then( //stuff ).

ps instead of the verbose findElement you can use $('#StartJobButton'). Its a convenience method described here: https://github.com/angular/protractor/blob/master/docs/getting-started.md

wlingke avatar Dec 13 '13 18:12 wlingke

Thank you, that worked.

DivsBellur avatar Dec 13 '13 18:12 DivsBellur