
|
Access to element coputed style
Hi,
I wonder if there's any way to get the computed style of an HTMLElement using the HTMLUnit Java API.
I noticed that HTMLUnit does parse CSS but couldn't figure out how to access the parsed info.
Thanks,
Amir
|

|
Re: Access to element coputed style
Hi Amir, There's no officially-supported public API to do this, but if hacks are OK then you can do: HtmlElement element = ...; ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle();
// use style Note that you'll be dealing with objects intended to be used by Rhino, so all the method names will have the funky "jsx" prefixes, but it should work... Take care, Daniel
-- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
|

|
Re: Access to element coputed style
Daniel,
It works like a magic.
Thanks a million,
Amir
gredler wrote:
Hi Amir,
There's no officially-supported public API to do this, but if hacks are OK
then you can do:
HtmlElement element = ...;
ComputedCSSStyleDeclaration style =
((HTMLElement)element.getScriptObject()).jsxGet_currentStyle();
// use style
Note that you'll be dealing with objects intended to be used by Rhino, so
all the method names will have the funky "jsx" prefixes, but it should
work...
Take care,
Daniel
On Fri, Jul 24, 2009 at 11:09 PM, AmirG <amirglatt@gmail.com> wrote:
>
> Hi,
> I wonder if there's any way to get the computed style of an HTMLElement
> using the HTMLUnit Java API.
> I noticed that HTMLUnit does parse CSS but couldn't figure out how to
> access
> the parsed info.
>
> Thanks,
> Amir
> --
> View this message in context:
> http://www.nabble.com/Access-to-element-coputed-style-tp24654513p24654513.html> Sent from the HtmlUnit - General mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Htmlunit-user mailing list
> Htmlunit-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/htmlunit-user>
--
Daniel Gredler
http://daniel.gredler.net/------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
|

|
Re: Access to element coputed style
Daniel, One additional question. I am trying to read the background-image property of an element using the ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle().jsxGet_backgroundImage() method.
It works fine. However, since sometimes the image urls are relative to a CSS file path and not to the html page path, I can't find a way to calculate the fully qualified url for some images.
Is there anyway to do that? Many thanks, Amir On Wed, Jul 29, 2009 at 5:18 PM, Daniel Gredler <djgredler@...> wrote:
Hi Amir,
There's no officially-supported public API to do this, but if hacks are OK then you can do:
HtmlElement element = ...; ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle();
// use style
Note that you'll be dealing with objects intended to be used by Rhino, so all the method names will have the funky "jsx" prefixes, but it should work...
Take care,
Daniel-- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
|

|
Re: Access to element coputed style
Hi Amir, I can't think of a way to do this without modifying the HtmlUnit source code... not even a hackish way. The problem is that you don't know which stylesheet the bg image attribute comes from... so you don't know what the path is relative to.
Sorry! Daniel On Sat, Oct 24, 2009 at 2:43 PM, Amir Glatt <amirglatt@...> wrote:
Daniel,One additional question. I am trying to read the background-image property of an element using the ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle().jsxGet_backgroundImage() method.
It works fine. However, since sometimes the image urls are relative to a CSS file path and not to the html page path, I can't find a way to calculate the fully qualified url for some images.
Is there anyway to do that? Many thanks, Amir On Wed, Jul 29, 2009 at 5:18 PM, Daniel Gredler <djgredler@...> wrote:
Hi Amir, There's no officially-supported public API to do this, but if hacks are OK then you can do:
HtmlElement element = ...; ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle();
// use style Note that you'll be dealing with objects intended to be used by Rhino, so all the method names will have the funky "jsx" prefixes, but it should work... Take care, Daniel -- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference _______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
-- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
|

|
Re: Access to element coputed style
Daniel, Thanks for your answer. I am wondering if there might be a way for me to modify the CSS files as HTMLUnit download them and to change all relative urls to absolute urls at this phase. What do you think? is there a way to do it?
Thanks, Amir On Mon, Oct 26, 2009 at 4:34 AM, Daniel Gredler <djgredler@...> wrote:
Hi Amir,
I can't think of a way to do this without modifying the HtmlUnit source code... not even a hackish way. The problem is that you don't know which stylesheet the bg image attribute comes from... so you don't know what the path is relative to.
Sorry!
Daniel
On Sat, Oct 24, 2009 at 2:43 PM, Amir Glatt <amirglatt@...> wrote:
Daniel, One additional question. I am trying to read the background-image property of an element using the ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle().jsxGet_backgroundImage() method.
It works fine. However, since sometimes the image urls are relative to a CSS file path and not to the html page path, I can't find a way to calculate the fully qualified url for some images.
Is there anyway to do that? Many thanks, Amir On Wed, Jul 29, 2009 at 5:18 PM, Daniel Gredler <djgredler@...> wrote:
Hi Amir, There's no officially-supported public API to do this, but if hacks are OK then you can do:
HtmlElement element = ...; ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle();
// use style Note that you'll be dealing with objects intended to be used by Rhino, so all the method names will have the funky "jsx" prefixes, but it should work... Take care, Daniel -- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference _______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
|

|
Re: Access to element coputed style
Hi Amir, Yeah that might work. Maybe try subclassing FalsifyingWebConnection and registering your custom web connection instance with the WebClient. Let us know if you get that to work :-) Take care, Daniel
On Wed, Oct 28, 2009 at 1:57 PM, Amir Glatt <amirglatt@...> wrote:
Daniel,Thanks for your answer. I am wondering if there might be a way for me to modify the CSS files as HTMLUnit download them and to change all relative urls to absolute urls at this phase. What do you think? is there a way to do it?
Thanks, Amir On Mon, Oct 26, 2009 at 4:34 AM, Daniel Gredler <djgredler@...> wrote:
Hi Amir,
I can't think of a way to do this without modifying the HtmlUnit source code... not even a hackish way. The problem is that you don't know which stylesheet the bg image attribute comes from... so you don't know what the path is relative to.
Sorry!
Daniel
On Sat, Oct 24, 2009 at 2:43 PM, Amir Glatt <amirglatt@...> wrote:
Daniel, One additional question. I am trying to read the background-image property of an element using the ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle().jsxGet_backgroundImage() method.
It works fine. However, since sometimes the image urls are relative to a CSS file path and not to the html page path, I can't find a way to calculate the fully qualified url for some images.
Is there anyway to do that? Many thanks, Amir On Wed, Jul 29, 2009 at 5:18 PM, Daniel Gredler <djgredler@...> wrote:
Hi Amir, There's no officially-supported public API to do this, but if hacks are OK then you can do:
HtmlElement element = ...; ComputedCSSStyleDeclaration style = ((HTMLElement)element.getScriptObject()).jsxGet_currentStyle();
// use style Note that you'll be dealing with objects intended to be used by Rhino, so all the method names will have the funky "jsx" prefixes, but it should work... Take care, Daniel -- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july_______________________________________________
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference _______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference _______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
-- Daniel Gredler http://daniel.gredler.net/
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
|