-1

I am trying to click on the 'Customer Login' button. But it does not.

module.exports = {
    tags: ['Registration'],
    'Test Registration Page' : function (client) {
         client 
         .url('http://www.globalsqa.com/angularJs-protractor/BankingProject/#/login') // Go to a url
         .waitForElementVisible('body', 1000) // wait till page loads
         .useXpath()
         .click('/html/body/div/div/div[2]/div/div[1]/div[1]/button')


       }
 };

2 Answers2

0

Replace

.click('/html/body/div/div/div[2]/div/div[1]/div[1]/button')

with

.click('//html/body/div/div/div[2]/div/div[1]/div[1]/button')

xPath expression sample //path/to/element

EDIT:

Other possibility can be using a CSS selector could be like this one:

div.borderM.box.padT20 div.center:first-child button.btn.btn-primary.btn-lg

in your case it will be:

useCss().click('div.borderM.box.padT20 div.center:first-child button.btn.btn-primary.btn-lg')

Also you have to make sure, that your page is loaded properly. For example by using .pause()

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
0

Instead of your current code block you can try the following code block with relative xpath as follows :

.click("//button[@class='btn btn-primary btn-lg'][@ng-click=\"customer()\"]")
# or
.click("//button[@class='btn btn-primary btn-lg' and contains(.,'Customer Login')]")

Update (from the comments)

The XPath being correct, instead of waiting till page loads, you can waitForElementVisible('xpath_of_element', 1000) and then invoke click() directly.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352