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.

Find a div with regexp and a number

Fabrice BFabrice B Members
edited November -1 in Sahi - Open Source
Hi all,


i've a question to a particular problem to find, highlight and click on a _div.

Like you see on the part of my html code below, i have a lot of DIV, and particulary 5 _div saw by recorder like this :
_div("gwt-Label[15]"). For each of gwt-Label a different id

My goal : Find my five _div("gwt-Label[ID]").


i try

_highlight(_div(3, _in($myPartOfHtml)));
_highlight(_div(4, _in($myPartOfHtml)));
_highlight(_div(5, _in($myPartOfHtml)));

but i find all of div


if i try

_highlight(_div(/gwt-Label/, _in($myPartOfHtml)));

I have the first one : _div(/gwt-Label/


My question : How to tell to sahi that i want the second, the fourth or other ID _div(/gwt-Label/ of $myPartOfHtml


where can i put my IDnumber of _div(/gwt-Label/ ?


Like this => _highlight(_div(/gwt-Label/[NUmber4], _in($myPartOfHtml)));

Thank u

Fabrice

<div class="gwt-Tree gwt-Tree-report" role="tree" style="position: relative; zoom: 1;" __eventBits="901" __listener="
<DIV style="POSITION: relative; ZOOM: 1" class="gwt-Tree gwt-Tree-report" role=tree __eventBits="901"><DIV hideFocus style="Z-INDEX: -1; POSITION: absolute; OUTLINE-STYLE: none; OUTLINE-COLOR: invert; OUTLINE-WIDTH: 0px; WIDTH: 198px; HEIGHT: 22px; FONT-SIZE: 0px; TOP: 109px; LEFT: 45px" role=treeitem tabIndex=0 aria-activedescendant=gwt-uid-63 __eventBits="6144"></DIV>
<DIV style="PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 0px; PADDING-TOP: 0px">
<TABLE style="WHITE-SPACE: nowrap">
<TBODY>
<TR>
<TD style="VERTICAL-ALIGN: middle"><IMG style="WIDTH: 9px; BACKGROUND: url(http://kimv2qualite2/app/F847160BF255A8C39C30F6C96E168E2A.cache.png) no-repeat -223px -21px; HEIGHT: 6px" border=0 src="http://kimv2qualite2/app/clear.cache.gif"></TD>;
<TD style="VERTICAL-ALIGN: middle">
<DIV style="DISPLAY: inline" aria-expanded=true id=gwt-uid-59 aria-level=1 class=gwt-TreeItem role=treeitem aria-posinset=1 aria-selected=true aria-setsize=1>
<DIV class=gwt-Label>RacineSportBoonenCombinatoire</DIV></DIV></TD></TR></TBODY></TABLE>
<DIV style="WHITE-SPACE: nowrap">
<DIV style="PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 16px; PADDING-TOP: 0px">
<TABLE style="WHITE-SPACE: nowrap">
<TBODY>
<TR>
<TD style="VERTICAL-ALIGN: middle"><IMG style="WIDTH: 9px; BACKGROUND: url(http://kimv2qualite2/app/F847160BF255A8C39C30F6C96E168E2A.cache.png) no-repeat -223px -21px; HEIGHT: 6px" border=0 src="http://kimv2qualite2/app/clear.cache.gif"></TD>;
<TD style="VERTICAL-ALIGN: middle">
<DIV style="DISPLAY: inline" id=gwt-uid-60 class=gwt-TreeItem role=treeitem>
<DIV class=gwt-Label>Boonen</DIV></DIV></TD></TR></TBODY></TABLE>
<DIV style="WHITE-SPACE: nowrap">
<DIV style="PADDING-BOTTOM: 3px; PADDING-LEFT: 13px; PADDING-RIGHT: 3px; MARGIN-LEFT: 16px; PADDING-TOP: 3px">
<DIV style="DISPLAY: inline" id=gwt-uid-61 class=gwt-TreeItem role=treeitem>
<DIV class=gwt-Label>Mondiaux</DIV></DIV></DIV></DIV></DIV>
<DIV style="PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 16px; PADDING-TOP: 0px">
<TABLE style="WHITE-SPACE: nowrap">
<TBODY>
<TR>
<TD style="VERTICAL-ALIGN: middle"><IMG style="WIDTH: 9px; BACKGROUND: url(http://kimv2qualite2/app/F847160BF255A8C39C30F6C96E168E2A.cache.png) no-repeat -223px -21px; HEIGHT: 6px" border=0 src="http://kimv2qualite2/app/clear.cache.gif"></TD>;
<TD style="VERTICAL-ALIGN: middle">
<DIV style="DISPLAY: inline" id=gwt-uid-62 class=gwt-TreeItem role=treeitem>
<DIV class=gwt-Label>Belgique</DIV></DIV></TD></TR></TBODY></TABLE>
<DIV style="WHITE-SPACE: nowrap">
<DIV style="PADDING-BOTTOM: 3px; PADDING-LEFT: 13px; PADDING-RIGHT: 3px; MARGIN-LEFT: 16px; PADDING-TOP: 3px">
<DIV style="DISPLAY: inline" id=gwt-uid-63 aria-level=3 class="gwt-TreeItem gwt-TreeItem-selected" role=treeitem aria-posinset=1 aria-selected=true aria-setsize=1>
<DIV class=gwt-Label>Copenhague (1)</DIV></DIV></DIV></DIV></DIV></DIV></DIV></DIV>">

Comments

  • tsivatsiva Members
    I am also having similar issues particularly with _div. I am not sure how to use DOM relation for the_div tag, when the _div is recording with index numbers. In my application we have lot of combo boxes with drop-down arrow in _div tag. I need to click on the div to select a value from the drop-down. I am using the same value that was recorded during replay. The indexes are changing most of the times and failing the script. I have recorded few scripts for validating different pages under one login session and then including all of them in a separate script and then running the script to complete the whole process validation at a time. Since all those files are running in the sequence, the indexing changes very frequently depending upon from where you start the main script. Here is a piece of my code for the _div section for your reference. I appreciate anyone's quick response since i was stuck at this point.

    I am using
    Sahi Pro trail version (latest build)
    IE9.0
    extjs4.1

    Here is my code sample:
    _click(_div(274));
    _highlight(_div("x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-last x-unselectable",_near(_label("SIC:"))));
    _click(_div(274));

    _click(_div(272));
    _highlight(_listItem("RETAIL TRADE"));
    _click(_listItem("RETAIL TRADE"));
    _click(_div(272));
    the value within the parenthesis changes very frequently.
  • TheeranTheeran Members
    Hi tsiva,

    Is the div recognized only by index?

    You can also try using _near, _under, _in APIs to access the particular div with reference to another element.

    Thanks,
    Theeran.
  • tsivatsiva Members
    Hi Theeran,
    Thanks for your quick response. Unfortunately the div is recognized only by the index. I have tried to use the _near but unable to recognize it during the replay. Any other thoughts from anyone?
  • TheeranTheeran Members
    Hi Tsiva,

    The div can be recognized in sahi controller by id, name, value, className, index.

    So try to use any one of these identifiers along with _near, _under, _in or combination of above mentioned Position Relational APIs to identify the element.

    If it doesnt help you, Please provide us the HTML code snippet and we will try to reproduce the same problem.

    Thanks,
    Theeran.
  • narayannarayan Administrators
    Hi Fabrice,

    Instead of a regular expression, please pass a string, like this:

    _highlight(_div("/gwt-Label/[4]", _in($myPartOfHtml)));

    Regards,
    Narayan
Sign In or Register to comment.