Nightwatch has its own method to get elements in a view. (In general, items should always be scrolled in a view from nightwatch / selenium. But if you want to do this manually, you can use getLocationInView ()
return this.getLocationInView('#myElement') .assert.visible('#myElement') .click('#myElement')
Nightwatch also supports this directly through the Webdriver Protocol, using moveTo () without any abstraction. In this case, it will look more:
const self = this; return this.api.element('#myElement', (res) => { self.api.moveTo(res.value.ELEMENT, 0, 0 () => { self.assert.visible('#myElement'); self.click('#myElement'); }) });
(it was written only on top, I hope that I was not mistaken)
But what can help in your case to change the scroll behavior of the seleniums element in config, for example:
firefox: { desiredCapabilities: { browserName: 'firefox', javascriptEnabled: true, acceptSslCerts: true, elementScrollBehavior: 1 } }
By default, 0 -> Elements scroll to the top of the page.
elementScrollBavior 1 -> Elements scroll at the bottom of the page
source share