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
| Nome | Tipo | Detalhes |
|---|---|---|
optionsopcional | object, boolean | opçõ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.behavioropcional | string | Veja Referência MDN. APENAS-WEB (Desktop/Mobile) |
options.blockopcional | string | Veja Referência MDN. APENAS-WEB (Desktop/Mobile) |
options.inlineopcional | string | Veja Referência MDN. APENAS-WEB (Desktop/Mobile) |
| Apenas Aplicativo Nativo Mobile | ||
options.directionopcional | string | Pode ser um de down, up, left ou right, o padrão é up. APENAS-APLICATIVO-NATIVO-MOBILE |
options.maxScrollsopcional | number | A quantidade máxima de rolagens até parar de procurar pelo elemento, o padrão é 10. APENAS-APLICATIVO-NATIVO-MOBILE |
options.durationopcional | number | A 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.scrollableElementopcional | Element | Elemento 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.percentopcional | number | A 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')
});
});