Pular para o conteúdo principal

scrollIntoView

Rola o elemento para a área visível tanto para Web Desktop/Mobile QUANTO para Aplicativos Nativos Móveis.

informação

A rolagem para Aplicativos Nativos Móveis é feita com base no comando móvel swipe.

Uso
$(selector).scrollIntoView({ behavior, block, inline, direction, maxScrolls, duration, scrollableElement, percent })
Parâmetros
NomeTipoDetalhes
options
opcional
object, booleanopções para Element.scrollIntoView(). Padrão para desktop/web móvel:
{ block: 'start', inline: 'nearest' }
Padrão para Aplicativo Nativo Móvel
{ maxScrolls: 10, scrollDirection: 'down' }
Apenas Desktop/Web Móvel
options.behavior
opcional
stringVeja Referência MDN.
APENAS-WEB (Desktop/Móvel)
options.block
opcional
stringVeja Referência MDN.
APENAS-WEB (Desktop/Móvel)
options.inline
opcional
stringVeja Referência MDN.
APENAS-WEB (Desktop/Móvel)
Apenas Aplicativo Nativo Móvel
options.direction
opcional
stringPode ser down, up, left ou right, o padrão é up.
APENAS-APLICATIVO-NATIVO-MÓVEL
options.maxScrolls
opcional
numberO número máximo de rolagens até parar de procurar o elemento, o padrão é 10.
APENAS-APLICATIVO-NATIVO-MÓVEL
options.duration
opcional
numberA duração em milissegundos para o deslize. O padrão é 1500 ms. Quanto menor o valor, mais rápido o deslize.
APENAS-APLICATIVO-NATIVO-MÓVEL
options.scrollableElement
opcional
ElementElemento usado para rolar dentro. Se nenhum elemento for fornecido, utilizará o seguinte seletor para iOS -ios predicate string:type == "XCUIElementTypeApplication" e o seguinte para Android //android.widget.ScrollView'. Se mais elementos corresponderem ao seletor padrão, por padrão ele escolherá o primeiro elemento correspondente.
APENAS-APLICATIVO-NATIVO-MÓVEL
options.percent
opcional
numberA porcentagem do elemento rolável (padrão) para deslizar. Este é um valor entre 0 e 1. O padrão é 0.95.
NUNCA deslize a partir do topo|fundo|esquerda|direita exatos da tela, você pode acionar, por exemplo, a barra de notificação ou outros recursos do SO/App que podem levar a resultados inesperados.
APENAS-APLICATIVO-NATIVO-MÓVEL
Exemplos
desktop.mobile.web.scrollIntoView.js
it('should demonstrate the desktop/mobile web scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to specific element
await elem.scrollIntoView();
// center element within the viewport
await elem.scrollIntoView({ block: 'center', inline: 'center' });
});

mobile.native.app.scrollIntoView.js
it('should demonstrate the mobile native app scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to a specific element in the default scrollable element for Android or iOS for a maximum of 10 scrolls
await elem.scrollIntoView();
// Scroll to the left in the scrollable element called '#scrollable' for a maximum of 5 scrolls
await elem.scrollIntoView({
direction: 'left',
maxScrolls: 5,
scrollableElement: $('#scrollable')
});
});

Welcome! How can I help?

WebdriverIO AI Copilot