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

click not working #1128

Closed ir-fuel closed 8 years ago

ir-fuel commented 8 years ago

Something strange happens when testing my Bootstrap website using Nightwatch.

I have the following element in my page definition:

    createAccountModalBackground: {
      selector:'div.modal-backdrop'
    }

In my test I execute the following code:

    subscribePage
      .click('@subscribeLiteButton')
      .waitForElementVisible('@createAccountModal', 1000)
      .waitForElementVisible('@createAccountModalBackground', 1000)
      .click('@createAccountModalBackground')

The click never gets executed. The modal stays on screen.

If however I replace the click call with:

      client.execute(function() {
        document.querySelector('div.modal-backdrop').click()
      })

It works fine.

Is there an issue somewhere?

Do you need more information?

beatfactor commented 8 years ago

The element is probably not visible at the time of the click. The Selenium click action works a bit different than the one from Javascript. You need to run your test with --verbose flag to identify what the issue is. In any case it doesn't look like a Nightwatch issue, if you're seeking assistance please use the Mailing List or StackOverflow.

ir-fuel commented 8 years ago

You are quick in closing this ticket, no? The line before doing this click I have: .waitForElementVisible('@createAccountModalBackground', 1000) so why are you concluding that the element is not visible at the time of the click? If it isn't visible that line should fail.

edit: running my tests shows me: Element <div.modal-backdrop> was visible after 48 milliseconds.

MateuszJeziorski commented 8 years ago

Maybe element is hovered by other element or you need to scroll down to the element? That would explain why this works fine

client.execute(function() {
        document.querySelector('div.modal-backdrop').click()
 })

Or you had luck and element disappear sometimes just after you check if the element is visible

Also, what do you mean The click never gets executed. The modal stays on screen. ? Is there any error?

ir-fuel commented 8 years ago

Thanks for the feedback. I'll investigate more and continue on Stackoverflow. Nice framework btw!

jovanialferez commented 7 years ago

got similar issue. your click workaround helps me a lot! thanks! :)

timetraveler90 commented 7 years ago

i am facing the same problem and that workaround doesnt work for me also.

atilacamurca commented 7 years ago

I had a similar issue and it turns out to be the library flatpickr, that when the calendar were open it was blocking the button.

So after I set a date I call .keys([''\uE00C'']) ('\uE00C' means ESC key) and the button were clickable again.

pushkalaP commented 6 years ago

I have the same issue, where click doesn't work with annotations everywhere I have a CSS path which is very lengthy. The application is developed in reactjs elements: { id : 'css path' }, commands:[{ .click('@id') // the above line doesnt work throws error .click ('css path') // this works }]

I don't understand what i am missing? Can anyone help me?