nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Clicking does not work #949

Closed naissa12 closed 8 years ago

naissa12 commented 8 years ago

When I try using the click function in nightwatch.js, sometimes it does not work. For example,

        .waitForElementVisible('.test')
        .pause(500)
        .click('.test')

When I run the command in verbose, it states that the click was a success, but nightwatch.js didn't actually click on the element; it didn't go to the next page. What should I do to fix this?

beatfactor commented 8 years ago

Looks like an issue with your test, not with nightwatch. Please note that the Mailing List is the appropriate tool to ask for assistance.

dbaronov commented 7 years ago

I have exactly the same issue. Have to use hacky approach which works:

      .waitForElementVisible('.c-clearing-search-widget__apply-btn', 10000)
      .click('.c-clearing-search-widget__apply-btn')
      .moveToElement('.c-clearing-search-widget__apply-btn', 0, 0)
      .mouseButtonClick(0)

Any idea why such a simple function does not work?

abstract-entity commented 7 years ago

Same for me, nightwatch do not do the click on some elements (for me it's a "a[id=LanguageButton]"). I've try in javascript and the click work : Ext.select("a[id=LanguageButton]").elements[0].click()

Dbaronov technic work, you save my day.

achikin commented 7 years ago

Pointless to say I have the same issue, so I'll just leave it here.

screen shot 2017-01-17 at 21 24 03
khodayarj commented 7 years ago

I faced the same issue, I'm putting several same click command to ensure one of them will work p.s : in my case the code below works :

       .moveToElement("//div[contains(@id,'btnGo-inner')]", 0, 0)
        .mouseButtonClick(0)
        .pause(1000)
        .moveToElement("//div[contains(@id,'btnGo-inner')]", 0, 0)
        .mouseButtonClick(0)
worldomonation commented 7 years ago

I thought I had a similar issue in mine, but putting on a waitForElement('element_selector') solved the issue for me. Not sure why it does not work for some, but I think maybe waiting for an element that would normally be loaded in after the button might help.

akuji1993 commented 7 years ago

This dev is pretty oblivious of this click issue while there are about 20 tickets that addressed this. In Selenium Webdriver, all of my clicks are working fine. When using Nightwatch and building the same test I did in vanilla Selenium, the clicks do not work. That doesn't look like a Selenium issue, it looks like a Nightwatch issue. We might abandon using Nightwatch, since there's obviously no good support from the developer and our tests are working a lot better in vanilla Selenium. Some issues are yours dude, not another libraries'.

mdurban commented 7 years ago

Yes, this issue needs to be reopened. Please leave unsolved issues (especially this one which has many issues opened about click() not working properly) open so others in the community can solve it if the developer can't get to it.

swoopedj commented 7 years ago

Replacing .click('div#my_div') with:

      .waitForElementVisible('div#my_div', 1000)
      .execute(selector => {
        document.querySelector(selector).click();
      }, ['div.my_div'])
      .moveToElement('div.my_div', 0, 0)
      .mouseButtonClick(0)

Not sure why this hack seems to work every time for me (on the one element I am having trouble clicking). I’ve tried several combinations of the different click commands mentioned in one of the previous comments, but removing click() from the mix has worked so far. This issue should be re-opened.

eldyvoon commented 6 years ago

Had the similar problem.

.pause(2000)
.assert.elementPresent('.SideNavigation > nav > ul > li:nth-child(17) > a')
.click('.SideNavigation > nav > ul > li:nth-child(17) > a')

I can pass the test with elementPresent. But the clicking using the exact selector does nothing.

mdurban commented 6 years ago

Quick question for those of you still seeing this issue. Does the button you're trying to link have an onClick that calls preventDefault()?

akuji1993 commented 6 years ago

In my case, no.

Natesuwhoa commented 6 years ago

If anyone is still having issues here, this worked for me:

.waitForElementVisible('button', 1000) .pause(1000) .click('button')

Just waiting and asserting that the element was there didn't work, but adding in a pause made it work.

Hopefully this helps!

shenxianpeng commented 6 years ago

Yes, I need always add .pasue() after waitForElementVisible(), I do not how about others framework works, IMHO it doesn't looks good.

3cL1p5e7 commented 6 years ago

@dbaronov thanks, you save my day :D

pedrohidalgo commented 6 years ago

I think the issue happens because sometimes we execute the test on a bigger screen (for example an external monitor with more resolution) and sometimes we execute the test with smaller screen resolution (for example a laptop's built-in monitor).

Imho the click sometimes doesn't work because maybe when testing against the smaller screen the element we want to click is not visible!!!.

ilearnio commented 6 years ago

Solved this problem for myself. For me the problem was that my element that I was trying to click was an element with 0 width and 0 height. But it had an inner svg tag which had some width and height, so I clicked on that svg instead.

But this is definitely a bug. Vanilla js .click() works fine on my element

markoglasgow commented 6 years ago

For people where @dbaronov solution doesn't work, or who want to use XPath, I found the following works for me:

https://gist.github.com/markoglasgow/49a5e76d1244ff25ffddce21b6dc211d

ivantw08 commented 5 years ago

not work for me too