Pular para o conteúdo principal

scrollIntoView

Rolar elemento para dentro da viewport para Web Desktop/Mobile E Aplicativos Nativos Mobile.

informação

A rolagem para Aplicativos Nativos Mobile é feita com base no comando mobile swipe.

Este comando funciona apenas com os seguintes componentes atualizados:

  • Servidor Appium (versão 2.0.0 ou superior)
  • appium-uiautomator2-driver (para Android)
  • appium-xcuitest-driver (para iOS)

Certifique-se de que seu ambiente Appium local ou baseado em nuvem seja atualizado regularmente para evitar problemas de compatibilidade.

Parâmetros
NomeTipoDetalhes
options
opcional
object, booleanopções para Element.scrollIntoView(). Padrão para desktop/mobile web:
{ block: 'start', inline: 'nearest' }
Padrão para Aplicativo Nativo Mobile
{ maxScrolls: 10, scrollDirection: 'down' }
Apenas Desktop/Mobile Web
options.behavior
opcional
stringVeja Referência MDN.
APENAS-WEB (Desktop/Mobile)
options.block
opcional
stringVeja Referência MDN.
APENAS-WEB (Desktop/Mobile)
options.inline
opcional
stringVeja Referência MDN.
APENAS-WEB (Desktop/Mobile)
Apenas Aplicativo Nativo Mobile
options.direction
opcional
stringPode ser um de down, up, left ou right, o padrão é up.
APENAS-APLICATIVO-NATIVO-MOBILE
options.maxScrolls
opcional
numberA quantidade máxima de rolagens até parar de procurar pelo elemento, o padrão é 10.
APENAS-APLICATIVO-NATIVO-MOBILE
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-MOBILE
options.scrollableElement
opcional
ElementElemento que é usado para rolar dentro. Se nenhum elemento for fornecido, ele usará 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-MOBILE
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/Aplicativo, o que pode levar a resultados inesperados.
APENAS-APLICATIVO-NATIVO-MOBILE
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