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.

.parentElement TypeError

globalwormingglobalworming Moderators
edited November -1 in Sahi - Open Source
Hi all

When executing a test i have a code i.e

var $a=_image("xy");
_log((_image("xy").parentElement.parentElement.title);
_log($a.parentElement.parentElement.title);

in the record tab, accessing the image by $a or by name works fine. When I play back this code, the line
_log((_image("xy").parentElement.parentElement.title);
works as expected, but
_log($a.parentElement.parentElement.title);
throws an error: TypeError: Cannot read property "parentElement" from undefined.

Does anyone have an idea why this is happening. Unfortunately I m relying on refering to pictures by a varible. This code is in a for-loop and I got many pictures :)

Regards
Wormi

Comments

  • Even I am facing the same problem on using the below code with Sahi Pro 4.5.2 version:

    var $Child = _table("/x-grid3-row-table.*/");
    var $Parent = $Child.parentElement.parentElement.parentElement.parentElement;

    Error displayed in log file:
    "Cannot read property "parentElement" from undefined"

    Please suggest a solution

    Regards,
    vinoth
  • I used parentNode instead of using parentElement in the above code and got the solution myself
  • Hi globalwarming,
    parentNode is an API that you are looking for.
    Repace parentElement with parentNode and you should be fine.
    var $a=_image("xy");
    _log((_image("xy").parentNode.parentNode.title);
    

    Regards.
This discussion has been closed.