We are trying to access the document object through WebAii c# code, that is in a unit test case.
we want to get the collection of images through the document object. We have a javascript library for webtrends that inserts images as external files. This is present in the document.images collection...but is not seen in the html source.
What is the code to see that the image exists, so that we know for sure that a webtrend call happens.
Thanks
Rad.
10 Answers, 1 is accepted
WebAii does not give you direct access to the document object, but can search the DOM for you and return found elements in wrapper classes. For example try this code after all the images are already loaded in the browser:
IList<HtmlImage> imageList = ActiveBrowser.Find.AllByTagName<HtmlImage>(
"img"
);
foreach
(HtmlImage anImage
in
imageList)
{
// Do something with each image in the list
}
This usually works because Test Studio searches the current DOM, not the original HTML sent to the browser. Regards,
Cody
the Telerik team
Test Studio Trainings

That is the point, there is no img tag for this external image that gets created by the webtrends javascript file.
It somehow appends it to the documents.images object but its not seen when i view source.
Its weird.
Radha.
document.images is quite literally a collection of all images contained in the browsers current DOM i.e. it's a list of all <img> tags currently present. Keep in mind that what the current DOM structure looks can have very little resemblance to what you see via View Source. View Source only shows you want the web server sent to the browser. It does not show you all the DOM changes that took effect as a result of JavaScript code running i.e. webtrends. The browser is not going to show an image unless there is an <img> tag in the live DOM, which is what Test Studio uses.
Did you try the code I sent you? I think you'll be surprised to find there really are a number of <img> tags in the live DOM as Test Studio scans it (once the images are loaded by the browser and JavaScript).
Kind regards,
Cody
the Telerik team
Test Studio Trainings

it doesn't work. I clearly see the image dcs.gif that gets added by webtrends in the chrome debugger under Resources tab,
Frames> BrowseByPage > Images > dcs.gif
but i do not see this .gif in the IList<HtmlImage> object
:(((
The only way i got around this problem, is by using a javascript function that checks for the existence of this image, I execute this from the test case using
var jsRetValue = Actions.InvokeScript("sl.sc.tracking.checkIfTrackImageExists();");
I wish that i could do this in the code instead.
Radha..
Another possibility is that the image you're after is located in an <iframe>. ActiveBrowser.Find only scans the main page, it does not scan any frames contained in that page. You have to specifically target the right frame to get at the elements on it. For example:
IList<
HtmlImage
> imageList = ActiveBrowser.Frames[1].Find.AllByTagName<
HtmlImage
>("img");
foreach(HtmlImage anImage in imageList)
{
// Do something with each image in the list
}
This will scan the second <iframe> (since Frames is 0 based).
The Chrome Developer tools is great for helping you figure out where an element is and how to locate it. It will show you the live DOM in the browser. You should be able to locate your tracking image and determine which iframe it's located in.
If you can send me a Fiddler trace of the page being loaded, I'll be able to investigate this as well and give you exact code for finding the tracking image. Greetings,
Cody
the Telerik team
Test Studio Trainings

I am after dcs.gif . (it is highlighted) and it is not present in any frames.
Also I want to clarify that we have a javascript object that holds a collection of images. This holds the dcs.gif image and as mentioned is not seen in html source...
The fiddler trace is below (cannot attach the session file with the message).
In line number 31 the image makes a webtrends call
# Result Protocol Host URL Body Caching Content-Type Process Comments Custom
1 200 HTTP localhost /Meijer/Entry/LandingContent?storeid=2648165&sneakpeek=N&listingid=0 84,716 private text/html; charset=utf-8 chrome:6152
2 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/button_input_skins.css 20,218 private text/css chrome:6152
3 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/site_wide.css 17,864 private text/css chrome:6152
4 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/entry.css 3,012 private text/css chrome:6152
5 200 HTTP Tunnel to s-static.ak.facebook.com:443 0 chrome:6152
6 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/sbscroller.css 2,714 private text/css chrome:6152
7 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/vertical_paddles.css 1,217 private text/css chrome:6152
8 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/nuep_nocontent.css 1,898 private text/css chrome:6152
9 504 HTTP static.crowdscience.com /start-4b95912b7f.js 512 text/html; charset=UTF-8 chrome:6152
10 200 HTTP uid.shoplocal.com /uid.aspx?callback=sl.sc.tracking.uidCallback 99 private text/html; charset=utf-8 chrome:6152
11 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/bbpage.css 7,261 private text/css chrome:6152
12 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/listingdetail.css 7,352 private text/css chrome:6152
13 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/storelocation.css 4,081 private text/css chrome:6152
14 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/bbgrid.css 5,240 private text/css chrome:6152
15 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/shoppinglist.css 3,773 private text/css chrome:6152
16 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/Styles/modal_dialog.css 204 private text/css chrome:6152
17 200 HTTP localhost /Meijer/Entry/GetViewBag?storeid=2648165&sneakpeek=N&listingid=0&callback=sl.sc.application.setViewBag 568 private application/javascript; charset=utf-8 chrome:6152
18 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/Meijer_sprite_BUTTONS.png 47,675 private image/png chrome:6152
19 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/Meijer_sprite_LOGOS.png 15,480 private image/png chrome:6152
20 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/Meijer_sprite_A.png 6,625 private image/png chrome:6152
21 304 HTTP localhost /Areas/SC5/_Template_201202/Content/Images/transparent/transparent1x1.png 0 max-age=21600 chrome:6152
22 200 HTTP localhost /SC5/_Template_201202/Content/Images/transparent/transparent1x1.png 110 private image/png chrome:6152
23 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/back_top.png 219 private image/png chrome:6152
24 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/back_middle.png 152 private image/png chrome:6152
25 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/back_bottom.png 230 private image/png chrome:6152
26 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/Meijer_Map.png 43,965 private image/png chrome:6152
27 200 HTTP localhost /SC5/MeijerGroup/Meijer/Content/images/Meijer_Map_Text.png 3,670 private image/png chrome:6152
28 200 HTTP www4.meijer.com /js/jquery.cookie.js?_=1363116574103 1,477 application/x-javascript chrome:6152
29 200 HTTP container.pointroll.com /event/?ctid=F08ADB3D-AE61-4627-A94C-0E42D5F82468&av=5774&eid=1362252574110.3872&ev=&item=&q=&val=&r=0.3251938030589372 898 private text/html; charset=utf-8 chrome:6152
30 200 HTTP www4.meijer.com /js/storeIdConvert.js?_=1363116574295 1,171 application/x-javascript chrome:6152
31 200 HTTP statse.webtrendslive.com /dcsby70ep100000086e12w4sw_6s7y/dcs.gif?&dcsdat=1363116574213&dcssip=localhost&dcsuri=/Meijer/Entry/LandingContent&dcsqry=%3Fstoreid%3D2648165%26sneakpeek%3DN%26listingid%3D0&WT.tz=-5&WT.bh=14&WT.ul=en-US&WT.cd=32&WT.sr=1680x1050&WT.jo=Yes&WT.ti=Berwyn%20Meijer%20Weekly%20Ads%20--%20Top%20Brands%20at%20Low%20Prices%20%7C%20Shop%20Today%20and%20Save&WT.js=Yes&WT.bs=1680x959&WT.fi=Yes&WT.fv=11.6&WT.sp=@@SPLITVALUE@@&WT.co_f=27a97a0aa2dffdeab501363111948174&WT.vt_sid=27a97a0aa2dffdeab501363111948174.1363111948174&WT.cg_n=Entry%20Page&WT.cg_s=entry&WT.si_p=main&WT.si_n=listconv&sl_retailer=Meijer&sl_storename=Meijer%207111%20Cermak%20Rd.%20Berwyn%2C%20IL%2060402&sl_storeid=2648165&LanguageID=1&sl_zipcnt=1&sl_zip=60402&sl_device=pc&sl_orientation=landscape 67 no-cache Expires: -1 image/gif chrome:6152
32 200 HTTP ev.ads.pointroll.com /event/?ss=44FD520E-6860-456C-B751-C7AD156362E5&av=5774&eid=1362252574110.3872&ev=&item=&q=&val=&r=0.5733151696622372 0 no-cache Expires: -1 chrome:6152
33 302 HTTP 20502103p.rfihub.com /ca.gif?rb=621&ca=20502103&ra=REPLACE_ME_WITH_YOUR_CACHE_BUSTING 0 no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT chrome:6152
34 200 HTTP 20502101p.rfihub.com /ca.gif?rb=621&ca=20502101&ra=REPLACE_ME_WITH_YOUR_CACHE_BUSTING 42 no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT image/gif chrome:6152
35 200 HTTP www4.meijer.com /weeklyads/takeover/settings.js?_=1363116576737 225 application/x-javascript chrome:6152
36 200 HTTP www4.meijer.com /weeklyads/meijer_page_scripts.js?_=1363116576799 1,084 application/x-javascript chrome:6152
37 200 HTTP www.facebook.com /fr/u.php?p=143062565833368&m=671599296113799582&t=2592000 73 public, max-age=0 Expires: Tue, 12 Mar 2013 12:29:39 PDT image/gif chrome:6152
38 304 HTTP www.meijer.com /favicon.ico 0 text/plain; charset=UTF-8 chrome:6152
39 301 HTTP g.msn.com /1ewenus50/news7?noCacheDummyParam=67fe412a-0365-4b6d-a164-17aa9f80ef50 0 no-cache, must-revalidate Expires: Fri, 01 Jan 1990 00:00:00 GMT mswinext:7688
40 200 HTTP rss.msnbc.msn.com /id/3054049/device/rss?noCacheDummyParam=67fe412a-0365-4b6d-a164-17aa9f80ef50 786 public Expires: Tue, 12 Mar 2013 19:39:20 GMT application/rss+xml; charset=utf-8 mswinext:7688
I did some more research on this using this page as a working example:
http://kb.webtrends.com/Support/SolutionDetail.aspx?Id=50130000000CBu3AAG&r=1
I have a much clearer understanding of what's going on here. You're right, the tracking image is not added to the DOM at all. JavaScript adds it to an internal memory only collection of images using this JavaScript code:
WebTrends.prototype.dcsCreateImage=function(dcsSrc){
if (document.images){
this.images[this.index]=new Image();
this.images[this.index].src=dcsSrc;
this.index++;
}
else{
document.write('<
IMG
ALT
=
""
BORDER
=
"0"
NAME
=
"DCSIMG"
WIDTH
=
"1"
HEIGHT
=
"1"
SRC
=
"'+dcsSrc+'"
>');
}
}
Since the image you're after only exists in the JavaScript world, invoking JavaScript will be the only way to get at it. I found I can get at the src value for dcs.gif image using this line of code in Test Studio:
string answer = Actions.InvokeScript<string>("_tag.images[0].src");
What I get back is this:
http://statse.webtrendslive.com/dcswxkx6r100004rra9vt8h0n_9g3z/dcs.gif?&dcsdat=1363124956392&dcssip=kb.webtrends.com&dcsuri=/Support/SolutionDetail.aspx&dcsqry=%3FId=50130000000CBu3AAG%26r=1&WT.co_f=757745389389228129&WT.vtid=757745389389228129&WT.vtvs=1363123120149&WT.tz=-5&WT.bh=16&WT.ul=en-us&WT.cd=24&WT.sr=1680x1050&WT.jo=Yes&WT.ti=How%20to%20test%20a%20SmartSource%20Data%20Collector%20installation%20|%20Webtrends%20Knowledge%20Base&WT.js=Yes&WT.jv=1.3&WT.ct=lan&WT.hp=0&WT.bs=1052x1237&WT.fv=10.0&WT.slv=Unknown&WT.tv=8.6.0&WT.dl=0&WT.ssl=0&WT.es=kb.webtrends.com/Support/SolutionDetail.aspx&WT.cg_n=Support&WT.cg_s=KnowledgeBase&WT.vt_f_tlh=1363123188&support=Unassisted&unassisted=1
Is this getting close? What information are you after pertaining to this particular tracking image?
P.S. By "sending me a Fiddler trace" what I really meant was save the trace to a .SAZ file and attach that file (after putting into a .zip file first). I can use that to simulate your web server and investigate deeper how your web page is behaving, along with the JavaScript.
Regards,
Cody
the Telerik team
Test Studio Trainings

Thanks. So i used my earlier solution of creating a javascript function that checks for the existance of this image in the javascript collection object.
Thanks.
Sounds good. Sorry it took a while to get to the bottom of this. I learned something too in this process I hadn't seen before.
Kind regards,Cody
the Telerik team
Test Studio Trainings

---------------------------------------------
http://www.toyswill.com