Closed naissa12 closed 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.
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?
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.
Pointless to say I have the same issue, so I'll just leave it here.
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)
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.
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'.
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.
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.
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.
Quick question for those of you still seeing this issue. Does the button you're trying to link have an onClick that calls preventDefault()?
In my case, no.
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!
Yes, I need always add .pasue() after waitForElementVisible(), I do not how about others framework works, IMHO it doesn't looks good.
@dbaronov thanks, you save my day :D
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!!!.
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
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
not work for me too
When I try using the click function in nightwatch.js, sometimes it does not work. For example,
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?