How to use regex in sahi script?
I am using sahi to automate the website, when I record the actions from the sahi recorder then it records the button click action (actually "span") as _click(_span("Done[4]"));
, but when I play the recorded script then it fails on that line as not found "Done [4]".
To solve this I just tried Regular Expression to click on _span("Done[4]")
, but no luck.
<br / "> HTML source structure: (this is displayed in the [ui-dialog, ui-widget] popup)
<div class="dashboardDlgButtonPanel">
<div id="addWidgetDone_wrapper" class="input_button ">
<div id="addWidgetDone" class="form_input_button">
<div class="buttonwrapper">
<a style="width: 49px; height: 41px; display: block;" id="addWidgetDone_Link" class="PrimaryButton" href="#" s1ignore="true" data-role="button" title="">
<span>Done</span>
</a>
</div>
</div>
</div>
<div id="addWidgetCancel_wrapper" class="input_button tertiaryButton">
<div id="addWidgetCancel">
<div class="buttonwrapper">
<a id="addWidgetCancel_Link" class="link" href="#" s1ignore="true" title="">Cancel</a>
</div>
</div>
</div>
</div>
I've tried the following after it:
_click(_span(/Done.*/));
_click(_span(/Done\\[[0-9]\\]/));
_click(_span(/Done\[[0-9]\]/));
_click(_span(/Done/i));
_click(_span("/Done/"));
_click(_span(new Reg Exp("Done\\[[0-9]\\]")));
_click(_span(/Done.*/,_near(_div("addWidgetDone_wrapper[1]"))));
_click(_span(/Done.*/,_near(_div(/addWidgetDone_wrapper\\[[0-9]\\]/))));
_click(_span(/Done.*/,_near(_div(/addWidgetDone_wrapper.*/))));
_click(_span(/Done.*/,_in(_div("addWidgetDone_wrapper[1]"))));
_click(_span(/Done.*/,_in(_div(/addWidgetDone_wrapper/))));
_click(_span(/Done.*/,_in(_div(/addWidgetDone_wrapper.*/))));
and many more other combinations, but none of them work.
Link link: sahi-link-1 , sahi-link- 2
Can anyone tell me what I am doing wrong?
Note: In the recorded action "Done [4]", the numeric part changes each time.
source to share
If the element was not found, the name is no longer correct, due to a structure change in your DOM, or the element is not actually theirs, which is what you should check first.
Try using:
// this means it will click on the fifth made -span element in your DOM
_click (_span ("/ Done / [4]"));
As for structure changes, try:
for(var $i = 0; $i<99; $i++){
var $I = JSON.stringify($i);
if (_isVisible(_span("Done["+$I+"]"))){
_click(_span("Done["+$I+"]"));
break;
}
}
source to share