click event for a link is not working for phantomjs

516 Views Asked by At

I am using nightwatchjs for end to end testing. My test passes for chrome, firefox, ie and edge but one of the test fails for phantomjs. click event for url seems to fail.

'do somethings' : function(browser) {
        browser
            .setValue('input[id=SearchInput]', '000')
            .click('button[id=Button]')
            .assert.containsText('label[id=nOutput]', '000')
            .click('a[id=link]')// this click is not working
            .pause(1000)
            .assert.value('input[id=Input]', 'A')
            .assert.value('input[id=InputB]', 'B')

            //reset page
            .click('button[id=__xmlview0--clearButton]')
            .end()
    },

Thanks for help.

1

There are 1 best solutions below

0
On

Looks like a Selenium issue.

https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/5404

Selenium first gets the element's position, then sends a mouse click event. If the element moved between the time, the element will not be clicked.

I've encountered this too, my test case is trying to click A, but B gets clicked. Still trying to figure out a solution.

In another project I also encountered another reason. The page is responsive-ready, some elements are display:none when browser width is less than, say, 1000px. When nightwatch launches Chrome or Firefox, the browser window is full screensize, but phantomjs's default viewport size triggers the responsive condition. So Selenium cannot even find the element I want to click.