Skip to content

Commit

Permalink
[FTR] Implement scrollIntoView util (#165080)
Browse files Browse the repository at this point in the history
## πŸ““ Summary

Based on the need for [this
test](https://github.com/elastic/kibana/pull/164493/files#diff-e0bb824023eef20a7b3742da023e25744a6c20406f59ae8400455c579153faeaR262)
to scroll into the element independently of its existence in view, this
PR exposes a new `scrollIntoView` method that replicates the behaviour
of the native [Element
.scrollIntoView](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
method.

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent c288c8b commit 56c04d8
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,32 @@ export class WebElementWrapper {
}

/**
* Scroll the element into view, avoiding the fixed header if necessary
* Scroll the element into view
*
* @param {ScrollIntoViewOptions} scrollIntoViewOptions
* @return {Promise<void>}
*/
public scrollIntoView(scrollIntoViewOptions?: ScrollIntoViewOptions) {
return this.driver.executeScript<void>(
(target: HTMLElement, options: ScrollIntoViewOptions) => target.scrollIntoView(options),
this._webElement,
scrollIntoViewOptions
);
}

/**
* Scroll the element into view if it is not already, avoiding the fixed header if necessary
* This method is a variation of the scrollIntoView method, where we only scroll into an element
* if it is not part of the "scrollable view".
* This implies a specific behavior, since the "scrollable view" of the view is identified by
* the `document.scrollingElement`, which always results to the html or body tag.
*
* Use cases:
* - An element (a section, a footer) is not visible in the whole page and we need to scroll into it.
* - An element is covered by the fixed header and we need to scroll into it ensuring is not covered.
*
* In case you have a scrollable list smaller that the size of the HTML document and you need
* to scroll into an element of that list, prefer using the `.scrollIntoView` method.
*
* @nonstandard
* @return {Promise<void>}
Expand Down

0 comments on commit 56c04d8

Please sign in to comment.