How can I scroll up and scroll down using TestCafe?
I tried window.scroll()
,
window.scrollTo()
and throws an error window is not defined.
How can I scroll up and scroll down using TestCafe?
I tried window.scroll()
,
window.scrollTo()
and throws an error window is not defined.
UPD: In v1.14.0 and later versions, you can use the following scroll methods: t.scroll, t.scrollBy, and t.scrollIntoView.
Old answer:
In your case, you can create your own ClientFunction
:
import { ClientFunction } from 'testcafe';
fixture `Fixture`
.page `https://github.com/DevExpress/testcafe`;
const scroll = ClientFunction(function() {
window.scrollBy(0,1500);
});
test(`test`, async t => {
await scroll();
await t.wait(1000);
});
The t.hover
action example:
// scroll to the "#some-element-scroll-to" element
await t.hover(Selector('#some-element-scroll-to'));
I had similar issue on Mac and used following to scrollIntoView of a know element in the page.
import { ClientFunction, Selector } from 'testcafe';
const scrollIntoView = ClientFunction( (selector: Selector) => {
const element = selector() as unknown as HTMLElement;
element.scrollIntoView();
});
fixture`HTMLElement`
.page('https://example.com');
test('Scroll element into view', async t => {
const bottomOfPage = Selector('#bottom-div');
await scrollIntoView(bottomOfPage);
});
Reference : Type cast page elements