Need help

27 views
Skip to first unread message

lokesh....@gmail.com

unread,
Apr 8, 2008, 11:40:12 AM4/8/08
to Watir General
Hi All,

I have to check the font-family, color and style of a particular text
\object. Can I do that using Watir\Ruby?

I am able to see that using IE Developer tool bar under Current style
tab.
but I want to check that using script.


Thanks in advance


Regards
Lokesh

Željko Filipin

unread,
Apr 8, 2008, 11:51:49 AM4/8/08
to watir-...@googlegroups.com
On Tue, Apr 8, 2008 at 5:40 PM, lokesh....@gmail.com <lokesh....@gmail.com> wrote:
> I have to check the font-family, color and style

Hi Lokesh,

I could help if you post some html.

Željko
--
ZeljkoFilipin.com

lokesh....@gmail.com

unread,
Apr 8, 2008, 1:10:35 PM4/8/08
to Watir General
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML Strict//EN"><META http-
equiv="Content-Type" content="text/html; charset=iso-8859-1">

<HTML class="dj_ie dj_ie7">
<HEAD><STYLE>
/* Rule 2 of ./style/unyte.css */
DIV {
FONT: 11px/130% verdana,arial,sans-serif;
COLOR: #4a4947
}

/* Rule 13 of ./style/unyte.css */
#main {
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
BACKGROUND-IMAGE: url(../images/common/bg_page.gif);
PADDING-BOTTOM: 0px;
MARGIN: 0px auto;
WIDTH: 783px;
PADDING-TOP: 70px;
BACKGROUND-REPEAT: repeat-y;
POSITION: relative;
BACKGROUND-COLOR: #ffffff;
TEXT-ALIGN: left
}

/* Rule 1 of ./style/unyte.css */
BODY {
FONT: 11px/130% verdana,arial,sans-serif;
COLOR: #4a4947
}

/* Rule 4 of ./style/unyte.css */
BODY {
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
MARGIN: 0px;
PADDING-TOP: 0px;
BACKGROUND-COLOR: #cccccc;
TEXT-ALIGN: center
}

/* Rule 99 of ./style/unyte.css */
.h1-fulfillment {
FONT-WEIGHT: bold;
FONT-SIZE: 18pt;
PADDING-BOTTOM: 20px;
COLOR: #3c5f84;
FONT-FAMILY: arial, helvetica, sans-serif
}

</STYLE></HEAD>
<BODY style="BACKGROUND: #ffffff"><DIV id="main">

<DIV class="h1-fulfillment">
&nbsp;&nbsp;Lotus Sametime Unyte
</DIV>

</DIV></BODY></HTML>



here I want to know the font-family, font size and color of the text
"Lotus Sametime Unyte"







On Apr 8, 8:51 pm, "Željko Filipin" <zeljko.fili...@gmail.com> wrote:
> On Tue, Apr 8, 2008 at 5:40 PM, lokesh.agra...@gmail.com <

Nathan Lane

unread,
Apr 8, 2008, 1:43:22 PM4/8/08
to watir-...@googlegroups.com
I'd like to know this too - I just did a bunch of tests on my own website, doing what I thought should work, and it appears as though there is a disconnect between Watir and the OLE object, for example:

ie.div(:index, 3).style.width  should have returned "760px"
ie.div(:index, 3).style["width"] should have returned "760px"

However both of those just returned "". My own website is hosted, and when I use IE Developer Toolbar in IE or Firebug in Firefox, I am clearly able to get these attributes out of the CSS. The only thing is that my div with index 3 does not have explicit styles, rather it has a class name. Does this affect the outcome of the above statements?

Nathan
--
Nathan Lane
Home, http://www.nathandelane.com
Mirror, http://nathandelane.awardspace.com

Paul Rogers

unread,
Apr 8, 2008, 2:56:59 PM4/8/08
to watir-...@googlegroups.com
you might need to use currentStyle to get the vaue, especially if it
is inherited from a other styles

Paul

Nathan Lane

unread,
Apr 8, 2008, 3:05:41 PM4/8/08
to watir-...@googlegroups.com
And how would one use currentStyle?

This usage is non-functional:

ie.span(:id, "homeLinkText").currentStyle

also

ie.span(:id, "homeLinkText").style.currentStyle

now obviously, when I look at the methods I'm not seeing anything named currentStyle. I am using Watir 1.5.3.

Paul Rogers

unread,
Apr 8, 2008, 3:11:58 PM4/8/08
to watir-...@googlegroups.com
no, youd have to implement it your self. search the archives for it,
some one else needd to do something like you are doing, and
currentStyle fixed it

If I get some time today I'll see if I can do something, but dont hold
your breath :-)


Paul

marekj

unread,
Apr 8, 2008, 7:19:44 PM4/8/08
to watir-...@googlegroups.com
Nathan,
The method is currentstyle.

ie.span(:id, "homeLinkText").document.currentstyle.attributeAsCameCase
or if you can't excecute directly use invoke.
ie.span(:id, "homeLinkText").document.currentstyle.invoke(attributeAsCameCase)

so for color you have invoke('color') but for background-color it's 'backgroundColor'

the ole_methods should show you the list of methods to call.
ie.span(:id, "homeLinkText").document.currentstyle.ole_methods

does that work for you?

marekj

Željko Filipin

unread,
Apr 9, 2008, 7:27:44 AM4/9/08
to watir-...@googlegroups.com
On Wed, Apr 9, 2008 at 1:19 AM, marekj <marek...@gmail.com> wrote:
> ie.span(:id, "homeLinkText").document.currentstyle.attributeAsCameCase

I did not know this.

This is so cool.

ie.div(:class, "h1-fulfillment").document.currentstyle.fontFamily
=> "arial, helvetica, sans-serif"

ie.div(:class, "h1-fulfillment").document.currentstyle.fontSize
=> "18pt"

ie.div(:class, "h1-fulfillment").document.currentstyle.color
=> "#3c5f84"

Željko

marekj

unread,
Apr 9, 2008, 10:07:17 AM4/9/08
to watir-...@googlegroups.com
That is cool indeed.
This is what I love about Watir. - it is a 'key' that 'unlocks' the entire world of DOM and OLE automation to the Internet Explorer. There is so much stuff there I get lost and I end up reading all this MSDN docs and DOM docs. Watir itself is a passage you use to explore this world.
So sometimes I just don't understand all those questions on the list like:  'can Watir do this or that or whatever' - I think the real power is that Watir is the 'passage' the 'key' the 'access' and it allows for all this OLE manipulation. I think Watir allows you to 'open' this world of DOM automation.
Certainly very cool library.

my 2 cents.

marekj

www.testr.us | Watir Automation

lokesh....@gmail.com

unread,
Apr 11, 2008, 9:43:28 AM4/11/08
to Watir General
Thanks Marekj and Željko.
it worked for me :)




On Apr 9, 7:07 pm, marekj <marekj....@gmail.com> wrote:
> That is cool indeed.
> This is what I love about Watir. - it is a 'key' that 'unlocks' the entire
> world of DOM and OLE automation to the Internet Explorer. There is so much
> stuff there I get lost and I end up reading all this MSDN docs and DOM docs.
> Watir itself is a passage you use to explore this world.
> So sometimes I just don't understand all those questions on the list like:
> 'can Watir do this or that or whatever' - I think the real power is that
> Watir is the 'passage' the 'key' the 'access' and it allows for all this OLE
> manipulation. I think Watir allows you to 'open' this world of DOM
> automation.
> Certainly very cool library.
>
> my 2 cents.
>
> marekj
>
> www.testr.us| Watir Automation
>
> On Wed, Apr 9, 2008 at 6:27 AM, Željko Filipin <zeljko.fili...@gmail.com>
> wrote:
>
>
>
> > On Wed, Apr 9, 2008 at 1:19 AM, marekj <marekj....@gmail.com> wrote:
> > > ie.span(:id, "homeLinkText").document.currentstyle.attributeAsCameCase
>
> > I did not know this.
>
> > This is so cool.
>
> > ie.div(:class, "h1-fulfillment").document.currentstyle.fontFamily
> > => "arial, helvetica, sans-serif"
>
> > ie.div(:class, "h1-fulfillment").document.currentstyle.fontSize
> > => "18pt"
>
> > ie.div(:class, "h1-fulfillment").document.currentstyle.color
> > => "#3c5f84"
>
> > Željko- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages