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.

DOM Relations - next to, below, below and above

j.gendersj.genders Members
edited November -1 in Sahi - Open Source
I just wrote some functions which i have found very useful. previously i was only using _in and _near to test several features on my website.

I have found that during my testing, i needed to test whether something was next to, above or above and below an element: code below.
<browser>
function nextTo ($element1, $element2){
    var $heightEl1 = _position($element1)[1];
    var $heightEl2 = _position($element2)[1];
    if ($heightEl1 == $heightEl2){
        return true;
    }
    return false;
}

function above($element1, $element2){
    var $heightEl1 = _position($element1)[1];
    var $heightEl2 = _position($element2)[1];
    if ($heightEl1 < $heightEl2){
        return true;
    }
    return false;
}

function belowAndAbove($element1, $belowElement, $aboveElement){
    var $heightEl1 = _position($element1)[1];
    var $heightEl2 = _position($belowElement)[1];
    var $heightEl3 = _position($aboveElement)[1];
    if ($heightEl1 > $heightEl2){
        if ($heightEl1 < $heightEl3){
            return true;
        }
    }
    return false;
}
</browser>

usage is:

_assertTrue(nextTo(_textbox("username"),_label("Username")));
_assertTrue(above(_textbox("username"),_password("password")));
_assertTrue(belowAndAbove(_password("password"), _textbox("username"), _submit("Login")));

Hope that this is useful.

Comments

  • narayannarayan Administrators
    Hi j.genders,

    This is great! Thanks a lot for sharing!

    Regards,
    Narayan
Sign In or Register to comment.