Share
Go down
Borisman
Posts : 5
Join date : 2014-01-16
Age : 25
Location : Indonesia

Get CSS value

on Thu Jan 16, 2014 5:24 pm
Hi all, i'm very new in Selenium, i would like to ask how to get CSS value with Selenium IDE ?

Thanks before.
ccox
Master
Master
Posts : 205
Join date : 2012-01-06
Age : 32
Location : Denver, CO

Re: Get CSS value

on Fri Jan 17, 2014 3:45 am
storeValue| css locator | variable

the css locator will be the location at which the variable you are looking to get is.

Then try
echo | ${variable}

That will write what the stored value is in the log
Borisman
Posts : 5
Join date : 2014-01-16
Age : 25
Location : Indonesia

Re: Get CSS value

on Fri Jan 17, 2014 8:32 am
Could you give me an example from this code ?

HTML :
Code:
echo <<<HTML
<div id="div1">text</div>
HTML;

CSS :
#div1
{ font-size: 12em; }


Thanks before.
ccox
Master
Master
Posts : 205
Join date : 2012-01-06
Age : 32
Location : Denver, CO

Re: Get CSS value

on Fri Jan 17, 2014 10:25 pm
Why are you using the css locator? You have an id.  In my opinion, id's are much better to use.

storeValue| id=div1| variable
echo | ${variable}
Borisman
Posts : 5
Join date : 2014-01-16
Age : 25
Location : Indonesia

Re: Get CSS value

on Sat Jan 18, 2014 12:03 am
No, what i mean is how to get the font-size value of that css code ?
ccox
Master
Master
Posts : 205
Join date : 2012-01-06
Age : 32
Location : Denver, CO

Re: Get CSS value

on Sat Jan 18, 2014 12:54 am
Try this:

storeEval |window.getComputedStyle(window.document.getElementById('div1'), null).getPropertyValue("font-size"); | variable

echo | ${variable}

This worked for me to get the font-size and all other css variables
ccox
Master
Master
Posts : 205
Join date : 2012-01-06
Age : 32
Location : Denver, CO

Re: Get CSS value

on Sat Jan 18, 2014 5:10 am
FYI, Selenium IDE doesn't have a built-in function for getting CSS attributes.  However, Selenium IDE is great at executing javascript using the storeEval and getEval commands.  You just have to implement the results of the execution to fit your needs.
Borisman
Posts : 5
Join date : 2014-01-16
Age : 25
Location : Indonesia

Re: Get CSS value

on Sat Jan 18, 2014 11:15 am
It's work! Thanks a lot.

Btw, i have a project which needs to store all HTML element property value, so i need to access not only HTML but CSS and javascript of the web.

Could you give me an advice which selenium i prefer to use to fit that needs ?
acts79
Posts : 3
Join date : 2014-02-18
http://ny.pe

Re: Get CSS value

on Wed Feb 26, 2014 4:31 pm
Finally found this one, thanks for posting. Really Helps
Sponsored content

Re: Get CSS value

Back to top
Permissions in this forum:
You cannot reply to topics in this forum