Public
Snippet $217 authored by Jérome Perrin

Selenium.getElementPositionTop debugging

Edited
selenium.js
// Code from https://lab.nexedi.com/nexedi/erp5/blob/master/product/Zelenium/selenium/core/scripts/selenium-api.js#L2347-2409 
// + some extra debugging comments.

var debug_getElementPositionTop = function(element) {
    var y = 0;

    while (element != null)
    {
        if(document.all)
        {
            if( (element.tagName != "TABLE") && (element.tagName != "BODY") )
            {
            y += element.clientTop;
            console.log("adding clientTop", element.clientTop, "(", y, ")", element);
            }
        }
        else // Netscape/DOM
        {
            if(element.tagName == "TABLE")
            {
            var parentBorder = parseInt(element.border);
            if(isNaN(parentBorder))
            {
                var parentFrame = element.getAttribute('frame');
                if(parentFrame != null)
                {
                    y += 1;
                }
            }
            else if(parentBorder > 0)
            {
                y += parentBorder;
            }
            }
        }
        y += element.offsetTop;
        console.log("adding offsetTop", element.offsetTop, "(", y, ")", element);

            // Netscape can get confused in some cases, such that the height of the parent is smaller
            // than that of the element (which it shouldn't really be). If this is the case, we need to
            // exclude this element, since it will result in too large a 'top' return value.
            if (element.offsetParent && element.offsetParent.offsetHeight && element.offsetParent.offsetHeight < element.offsetHeight)
            {
                // skip the parent that's too small
                element = element.offsetParent.offsetParent;
                console.error("ohoho skipping");
            }
            else
            {
            // Next up...
            element = element.offsetParent;
        }
       }
    return y;
};

debug_getElementPositionTop(document.getElementById('group_1_activity_1_block_1'));