Scroll the page or active element in any direction using mouse wheel or keyboard.
Focus RequirementsScrolling requires the page or a frame to be focused. If an input field or other interactive element has focus, scroll commands may not work as expected. Before scrolling, ensure focus is on the page by:
Clicking on a non-interactive area (e.g., page background)
Pressing the Escape key to unfocus interactive elements
Clicking outside of input fields or text areas
If scroll is still not working, try using Page Down/Page Up keys directly:
Copy
await testdriver.pressKeys(['pagedown']); // Scroll downawait testdriver.pressKeys(['pageup']); // Scroll up
direction (string) - Scroll direction (default: 'down')
maxDistance (number) - Max pixels to scroll (default: 10000)
textMatchMethod (string) - 'turbo' or 'ai' (default: 'turbo')
method (string) - 'keyboard' or 'mouse' (default: 'keyboard')
invert (boolean) - Scroll until text disappears (default: false)
Examples:
Copy
// Scroll down until "Contact Us" appearsawait testdriver.scrollUntilText('Contact Us');// Scroll up to find textawait testdriver.scrollUntilText('Header', 'up');// Scroll until text disappearsawait testdriver.scrollUntilText('Loading...', 'down', 5000, 'turbo', 'keyboard', true);// Use AI matching for fuzzy textawait testdriver.scrollUntilText('footer content', 'down', 10000, 'ai');
// After typing in an input, unfocus it firstawait testdriver.find('email input').click();await testdriver.type('user@example.com');// Click elsewhere or press Escape before scrollingawait testdriver.pressKeys(['escape']);// Or click a non-interactive area// await testdriver.find('page background').click();// Now scroll will work properlyawait testdriver.scroll('down', 300);// If scroll still doesn't work, use Page Down directly// await testdriver.pressKeys(['pagedown']);
Choose the right scroll method
Copy
// For web pages, mouse scroll is usually smootherawait testdriver.scroll('down', 300, 'mouse');// For desktop apps or when mouse doesn't workawait testdriver.scroll('down', 300, 'keyboard');
Use scrollUntil for dynamic content
Copy
// Instead of guessing scroll amountawait testdriver.scrollUntilText('Load More button');const loadMoreBtn = await testdriver.find('Load More button');await loadMoreBtn.click();
Set reasonable max distance
Copy
// Avoid infinite scrollingawait testdriver.scrollUntilText('Footer', 'down', 5000); // Max 5000px
Keyboard scroll uses Page Down/UpKeyboard scrolling typically moves by one “page” at a time, which may be more than the specified pixel amount. It’s more compatible but less precise than mouse scrolling.
// Scroll to load more buttonawait testdriver.scrollUntilText('Load More');const loadBtn = await testdriver.find('Load More button');await loadBtn.click();await new Promise(r => setTimeout(r, 2000));
Find Element in Long List
Copy
// Scroll through list to find itemawait testdriver.scrollUntilText('Product #42');const product = await testdriver.find('Product #42');await product.click();
Infinite Scroll
Copy
// Scroll multiple times for infinite scrollfor (let i = 0; i < 5; i++) { await testdriver.scroll('down', 500); await new Promise(r => setTimeout(r, 1000)); // Wait for load}
Horizontal Gallery
Copy
// Navigate horizontal carouselawait testdriver.scroll('right', 300);await new Promise(r => setTimeout(r, 500));const nextImage = await testdriver.find('next image in carousel');await nextImage.click();