-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,191
  • 4
  • 17
  • 37
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.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • @kunalbhaskar Check the updated code and let me know the status please – DebanjanB May 24 '18 at 12:35
  • Now syntax is fine, but still it does not able to click on the Customer Login button – kunal bhaskar May 24 '18 at 12:41
  • Instead of _waiting till page loads_, can you `waitForElementVisible('xpath_of_element', 1000)` and then invoke `click()` directly? – DebanjanB May 24 '18 at 12:44
  • I use .pause(5000). Now, it's working. Thanks for your support – kunal bhaskar May 24 '18 at 13:48
  • @kunalbhaskar Great News !!! If my _Answer_ have catered to your _Question_ please [_Accept_](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) the _Answer_ by clicking on the hollow check mark beside my _Answer_ which is just below the _VoteDown_ arrow so the check mark turns _green_ . – DebanjanB May 24 '18 at 13:49