How to scroll to a particular element on a web page in JS-Nighwatch?

What to do to scroll to a particular element on a webpage in Nighwatch?

Hi Devan,

To scroll to a particular element on a webpage in Nighwatch, you can refer to the below command format:

module.exports = { ‘Scroll to Element Test’: function (browser) { // Replace ‘your_selector’ with the actual selector of the element you want to scroll to const elementToScrollTo = ‘your_selector’;

browser
  .execute('scrollTo(0, document.querySelector("' + elementToScrollTo + '").offsetTop);')
  // Your test actions/assertions go here
  .end();

} };

In this example, the execute command executes a JavaScript snippet that scrolls the page to make the specified element visible. Replace ‘your_selector’ with the actual selector of the element you want to scroll to.

To learn how to scroll on a webpage in any direction, follow this guide below.