Interaction Snippets

Interaction snippets can be used to interact with elements on a webpage that your automation has navigated to.

# Automating scrolling


To instruct your automation to scroll, you can do so once you have the class of the containing element, for example:

await page.locator('container').scroll({
    scrollLeft: 30,
    scrollTop: 10
})

# Retrieving and filtering elements


Retrieving elements is a great way to ensure that you're interacting with the right one - but there are cases where there may be two elements with the same attributes. To filter these out, the following can be used:

await page.locator('button').filter(button => button.innerText === 'Add to basket').click();

This will ensure that the automation will only click buttons that have the button class, but also have their inner text set to 'Add to basket' - great for automating e-commerce sites, or pages that may have differing structures.