18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
get style from jQuery Object
in Sahi Pro
Hi,
I'm new guy for using sahi. and I want to know how to get style from jQuery Object.
I want to get background Color from following object, but the backgroundColor is determined by class.
when I used function: _style($divObj, 'backgroundColor') or _style($divObj, 'background-color'), it returns null.
So I used _eval() funtion to get css attribute from jQuery Object, and It can return backgroundColor like this: rgb(59,75,91). but when I pass the object "$var1" to rgbToHexUpCase() function, it can not finish the string connection using character "+", concat function, and array.join() fucntion. and It always return : //#NANNANNAN
so, my question:
1. why is #NANNANNAN after concating with each element?
2. has any better ideas for getting css from class?
3. the detail instructions about _eval() function:
I'm new guy for using sahi. and I want to know how to get style from jQuery Object.
I want to get background Color from following object, but the backgroundColor is determined by class.
when I used function: _style($divObj, 'backgroundColor') or _style($divObj, 'background-color'), it returns null.
So I used _eval() funtion to get css attribute from jQuery Object, and It can return backgroundColor like this: rgb(59,75,91). but when I pass the object "$var1" to rgbToHexUpCase() function, it can not finish the string connection using character "+", concat function, and array.join() fucntion. and It always return : //#NANNANNAN
so, my question:
1. why is #NANNANNAN after concating with each element?
2. has any better ideas for getting css from class?
3. the detail instructions about _eval() function:
html:
<div id="__button202" data--ui="__button202" data--automation-id="multiTab-B-nonProspectUser" class="ClientMTabButton ClientMTabButtonIconVisible ClientMTabButtonSelected MBarChild">
my sahi code:
var $Obj=_byXPath("//div[@data-automation-id='multiTab-B-nonProspectUser' and contains(@class,'ClientMTabButtonSelected')]");
var $var1=_eval("$(" + $Obj + ").css('backgroundColor')"); //it can return background Color like this: rgb(59,75,91)
rgbToHexUpCase($var1);
function rgbToHexUpCase($rgbColor){
_log("[rgbToHexUpCase], input parameter:"+$rgbColor+", type:"+typeof($rgbColor));
var $stop = $rgbColor.indexOf(")");
var $result, $tmp;
if($rgbColor.indexOf("rgba")>-1){
$tmp = $rgbColor.substring(5, $stop);
}else{
$tmp = $rgbColor.substring(4, $stop);
}
$result = $tmp.split(",",3);
var $r=rgbUCase($result[0].trim()); //3B
var $g=rgbUCase($result[1].trim());//4B
var $b=rgbUCase($result[2].trim());//5B
var $rtn1="#"+$r+$g+$b;
_log("[rgbToHexUpCase], value:" + $rtn1); //#NANNANNAN
return $rtn1;
}
function rgbUCase($rgbValue){
_log("[rgbUCase], input param:" + $rgbValue + ", type:" + typeof($rgbValue));
var $hex = Number($rgbValue).toString(16).toUpperCase();
if($hex.length <2){
$hex = "0"+ $hex;
}
return $hex;
}