Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
33
rated 0 times [  35] [ 2]  / answers: 1 / hits: 26481  / 9 Years ago, mon, february 23, 2015, 12:00:00

I apologize if this is a newbie question, just starting out with web automation testing.



I want to test a login screen page. Finding the name and password textfields was easy (just used by.model), however I am having issues locating the login button with my script.



I googled around and I should be able to find an element by className using element(by.css(.className)), however this fails to work and I am always getting NoSuchElementError: No element found using locator: By.cssSelector(.btn btn-lg btn-primary btn-block).



Any idea what I am doing wrong?



Thanks you in advance,



LoginBtn HTML:



<button class=btn btn-lg btn-primary btn-block type=submit ng-disabled=loading>login</button>


My code:



describe('Test login', function() {
var username = element(by.model('formData.email'));
var password = element(by.model('formData.password'));
var loginBtn = element(by.css('.btn btn-lg btn-primary btn-block'));


beforeEach(function() {
browser.get('some site'); //hidden on purpose
});

it('should have a title', function() {
username.sendKeys(1);
password.sendKeys(2);
loginBtn.click();


});


});

More From » angularjs

 Answers
34

If you are checking for multiple classes, separate them with dots:



by.css('.btn.btn-lg.btn-primary.btn-block')


Though, I'd find the button by text - looks more reliable and readable:



by.xpath('//button[. = login]')





Also, think about assigning the button an id (if this is under your control) attribute to ease the testing process:



<button id=submitButton class=btn btn-lg btn-primary btn-block type=submit ng-disabled=loading>login</button>


Then, it would be as easy as:



by.id('submitButton')

[#67703] Friday, February 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lindsay

Total Points: 402
Total Questions: 109
Total Answers: 109

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;