views:

560

answers:

3

Hi everybody.

I am trying to get the value of a "Background-image"-tag in a stylesheet which is used on my web-site. The style-sheets are referenced from the HTML file as follows:

<style media="all" type="text/css">
    @import "master.css";
</style>
<style media="all" type="text/css">
    @import "layout.css";
</style>

The layout.css file contains:

#frontpage-main-features {
    background: url('../elms/frontpage-main-gradient.jpg') no-repeat left top;
    margin-bottom: 10px;
}
#frontpage-main-features-inner {
    width: 700px;
    padding: 20px 20px 10px 20px;
    background: url('../elms/frontpage-main-gradient-bottom.jpg') no-repeat left bottom;
}

In the master.css file a background image is referenced which is then overloaded in the layout.css file by the #frontpage-main-features-inner section. I would very much like to access the "background"-tag in order to see which background image is currently being shown in a specific part of the page. Any suggestions?

Best,

Michael

+2  A: 

Why not just use FireBug / the IE8 dev console? load the page, open the console, find the piece of html you are looking for and inspect the css properties, it will give you all applied styles for that element, overridden properties will be striked through...

Colin
I do use Firebug/IEdeveloper and am able to get the properties that way, but I was trying to get the programmatically. See below..:)
Michaelg
+1  A: 

You're talking about looking at the markup of the page from C#, i.e. this is the markup that is not an ASP.Net server control and is not viewable by ASP.Net.

Sorry, that's not possible using ASP.Net. You can only view data that is marked for server to view.

Why do you need this? There could be another way to do whatever you are trying to do. Maybe you need to turn the problem around (get markup to get the class name from c#) which is easier.

Cyril Gupta
I am trying to verify the presence of a specific background image on a page using Selenium. The image can be overloaded by different css-files and it is thus not directly visible in the HTML code. Could you give an example of what you are suggesting - maybe it will turn on the lightbulb in my brain..:-)
Michaelg
A: 

The problem is that CSS rules are not applied or enforced on the server, they are applied by the client browser. You could perhaps create a parser that goes through the referenced CSS files and figures out what image should be displayed but you really can't know with certainty how the client browser will interpret and apply the CSS rules.

Venr
Yep I found out. The idea of checking the image through accessing and parsing the css file came up in the brain storm we had, but it doesn't solve the problem that I need to see which image is being rendered by the browser. I was considering the possibility of hooking directly into the render engine of the browser but I don't know if that is possible. As far as I see it, the only solution is to parse the HTML-file, extract the links to the css-files, determine which is the latest one containing a reference to a bg-image in the section I need to check and then that has to suffice. Thanks..:-)
Michaelg