18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Identification of Scroll bar

ShwethaShwetha Members
edited November -1 in Sahi - Open Source
Hi,
I have a requirement for identifying scroll bars in a web page. Can anyone please help me in identifying scroll bars through Sahi. The scroll bars are not identified when spyed. Is there any function or other method to do this?

Comments

  • narayannarayan Administrators
    Shwetha,

    Can you tell why you want to identify the scrollbar? What is the end goal?
    Javascript does not allow you to directly access the scrollbar, though you can scroll to a particular point on the page.

    Regards,
    Narayan
  • ShwethaShwetha Members
    actually I just need to check if the scroll bar is present when more number of events are present. I dont need to use the scroll bar or scroll page. I just want to identify if scroll bar is present.
  • beesmanbeesman Members
    var $nHeight = _eval("document.body.scrollHeight");
    var $nTop = _eval("document.body.scrollTop");
    var $nCHeight = _eval("document.body.clientHeight");
    _alert($nHeight + " " + $nTop + " " + $nCHeight);
    if (_condition($nHeight > ($nTop + $nCHeight))) {
    //bar present
    }else{
    //bar not present
    }
  • narayannarayan Administrators
    Hi Beesman,

    Thanks for the answer. I have a question though. Why is the scrollTop being added to the scrollHeight?
    Would it not suffice to just check if scrollHeight is greater than clientHeight?
    We will also need to check that the overflow property of style is not "hidden".

    Some info: http://www.quirksmode.org/dom/w3c_cssom.html

    I am adding the overflow property check to your solution, removing scrollTop and moving it into a browser function. Let me know if this works for you.
    <browser>
    function hasScrollBar(el){
       return (el.scrollHeight > el.clientHeight && _style(el, "overflow") != "hidden");
    }
    </browser>
    
    _assert(hasScrollBar(document.body));
    
    // or for a div
    _assert(hasScrollBar(_div("myDiv")));
    
    // or use an element's ownerDocument to get to its parent document object
    // _link("myLink").ownerDocument.body) may be used to find the frame's body in which _link("myLink") is.
    _assert(hasScrollBar(_link("myLink").ownerDocument.body));
    
    

    Regards,
    Narayan
  • beesmanbeesman Members
    edited July 2009
    >>Why is the scrollTop being added to the scrollHeight?

    it's not necessary to add the scrollTop .
    if u want to know whether the scrollbar scrolled to the bottom. scrollTop is necessary .
  • narayannarayan Administrators
    Got it. Thanks.
  • Hi Narayan,

    In one of the above comments you mentioned
    "Javascript does not allow you to directly access the scrollbar, though you can scroll to a particular point on the page."

    I want to scroll down but sahi fails to identify that, could you please give a solution to that.

  • @rajivpamidi

    you could use _focus($element). The viewport will be moved so that this $element is visible.

    Regards
    Wormi
  • Hi Wormi,
    Thanks for the reply... but the scroll bar is an infinite scroll bar, I was able to assert if the scroll bar is present or not using Narayan's code in the above comments but could not focus on that scroll bar since it does not have a unique div id .
  • Hi,
    Even i have similar issue,like objects get loaded only when we scroll like in FB .so if i want to find the object and click what i can do for it?
Sign In or Register to comment.