# Automate Scrolling in Scenario Editor

<div id="bkmrk-when-element-is-not-">When element is not visible in the table view, we need to scroll down till element gets visible in the table view.

Ex:- Patient Number "L100" is not visible in the below table view, So we need to click the Scroll bar till element gets visible in the table view.

 ![](https://docs.appvance.net/uploads/images/gallery/2026-07/scaled-1680-/qbOJbUabilocV6T1-0f98dde9df58.png)

To achieve above scenario sahi API provides the "**scrollTop**" function.

Below is the sample sahi code to automate the above scenario.

\_div("pt1:r2:0:pc1:pt\_t1::scroller") is the Scrollbar element in the respective Application (This Scrollbar element may vary from application to application).

"Scrollbar-element.scrollTop" is the syntax to simulate the mouse hover and click scrollbar.

 ![](https://docs.appvance.net/uploads/images/gallery/2026-07/scaled-1680-/F7Yid16YHxWZUPaB-c9d57ee9f4e7.png)

Used while loop in the code to iterate click scrollbar multiple times till element gets visible in the table view.

 </div><u>**SCROLLING FUNCTION USAGE IN TEST DESIGNER:**</u>

There are various approaches one can use to do scroll – be it vertical/horizontal.Those are below:

Use CustomJS action from Action dropdown while using in scripts.Try these in browser's console before using in scripts.

<u>JAVASCRIPT APPROACHES:</u>

1.document.getElementById(&lt;id&gt;).scrollTo(1000,0) -----------→ &gt; This is to horizontal scrolling – y co-ordinates would be zero. you can try with x coordinate value of any number.

 document.getElementsById(&lt;id&gt;).scrollTo(0,1000) ----------→ This is for Vertical scrolling - X co-ordinates would be zero. you can try with y coordinate value of any number.

Following will retrieve a list of elements matching this class .So accordingly we have to select the correct element to do the scroll.

2.document.getElementsByClassName(&lt;classvalue&gt;)

 document.getElementsByClassName(&lt;classvalue&gt;)\[1\] – 2nd element from the list..

 document.getElementsByClassName(&lt;classvalue&gt;)\[1\].scrollTo(1000,0)

3.document.getElementsByName(&lt;name&gt;) – name of element — document.getElementsByName(&lt;name&gt;)\[1\].scrollTo(1000,0)

4.document.getElementsByTagName(&lt;tagname&gt;) – tagname of element — document.getElementsByTagName(&lt;tagname&gt;)\[1\].scrollTo(1000,0)

5.document.getElementsByTagNameNS(&lt;namespace&gt;,&lt;tagname&gt;) – name of element — document.getElementsByTagNameNS(&lt;namespace&gt;,&lt;tagname&gt;)\[1\].scrollTo(1000,0)

Usage in Script – \_eval("document.getElementById(&lt;id&gt;).scrollTo(1000,0)") — wrap the above in \_eval("") to be used in script in ds or js scripts.

<u>JQUERY APPROACHES:</u>

Normal jquery selectors can be used – as ds$('#id') , ds$('.classvalue') ,etc..

 ds$('#id').scrollTop(500) — &gt; This will scroll vertically

 ds$('#id').scrollLeft(500) — &gt; This will scroll horizontally.

Usage in Script – \_eval(" ds$('#id').scrollTop(500)") - wrap the above in \_eval("") to be used in script in ds or js scripts.

<u>XPATH APPROACHES:</u>

If there are no proper identifiers for the element such as no class/id/name/title or any other attribute , then one can go by XPATH – relative or absolute XPATH. Inspect the element .Then right click element in inspect panel – click copy – then click xpath/selector options etc to be used for scrolling.

 ![](https://docs.appvance.net/uploads/images/gallery/2026-07/scaled-1680-/pNQuzfv8mdZ4Sifv-f918c465711a.png)

usage of XPATH to use in scrollTo:

 ![](https://docs.appvance.net/uploads/images/gallery/2026-07/scaled-1680-/rLRZ7AeJOpMNGoGk-291135817766.png)

Eval in Browser as action and value to be used is - \_ds.byXPath("//\*\[@id='dtHorizontalExample\_wrapper'\]/div\[2\]/div/div/div\[2\]").scrollTo(200,0) — This is for horizontal scrolling. Same can be used for vertical scroll except the coordinates data 0,200. as in \_ds.byXPath("//\*\[@id='dtHorizontalExample\_wrapper'\]/div\[2\]/div/div/div\[2\]").scrollTo(0,200)

<div id="bkmrk-last-updated%3A-june-2">---

Last updated: <span class="mc-variable General.NewDateTimeVariable variable">June 26, 2023</span>

If you have any feedback on this topic, please contact us at <documentation@appvance.ai>

</div>