Show List

Scroll

Here's a sample TestCafe test script that demonstrates working with scroll to element and scroll page actions:


import { Selector } from 'testcafe'; fixture('Scroll Test') .page('https://www.example.com'); test('Perform Scroll Actions', async t => { // Selector for the element to scroll to const scrollToElement = Selector('#scroll-to-element'); // Scroll to the element await t .scrollTo(scrollToElement); // Scroll the page by 500 pixels vertically and 0 pixels horizontally await t .scrollBy(0, 500); });

In this test:

  • We import the Selector function from TestCafe to select elements on the web page.
  • We define a fixture named 'Scroll Test' and set the page to 'https://www.example.com'.
  • Inside the test function, we define a selector for the element we want to scroll to (replace '#scroll-to-element' with an appropriate selector for your web page).
  • We use TestCafe's scrollTo action to scroll to the specified element.
  • We use TestCafe's scrollBy action to scroll the page vertically by 500 pixels and horizontally by 0 pixels.

Make sure to replace 'https://www.example.com' with the URL of the website you want to test, and adjust the selector accordingly based on the structure of the webpage you are testing.


    Leave a Comment


  • captcha text