Web document caption

Class library usage, coding and language questions.
anzacthecat
Posts: 31
Joined: Mon Jan 10, 2011 1:05 pm

Web document caption

Post by anzacthecat » Fri Jun 03, 2011 12:08 pm

How can I find out what the caption of the current Web Document is?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Web document caption

Post by Ciege » Fri Jun 03, 2011 3:59 pm

While using a valid DOM object get the caption property of the element.

Code: Select all

string strCaption = myDom.Element.GetAttributeValue("Caption").ToString();
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Web document caption

Post by Support Team » Mon Jun 06, 2011 2:47 pm

While ciege's way works like a charm :D the Ranorex recommended way using adapters is the following:
Ranorex.WebDocument doc = ...;
Container docCont = new Container(doc);
string caption = docCont.Caption;
This code works, since every WebDocument also supports the Container adapter, providing a Caption attribute, as can be seen in the Overview tab page in Ranorex Spy.

Regards,
Alex
Ranorex Team
.
Image

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Web document caption

Post by Ciege » Mon Jun 06, 2011 3:47 pm

Because you said "the Ranorex recommended way..." is there a reason why I should use your code or should not use my code? Since my method is not recommended, does that mean that I am potentially setting myself up for a future failure? Is one way really better than the other?

Thanks!
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Web document caption

Post by Support Team » Mon Jun 06, 2011 3:56 pm

Ciege wrote:Because you said "the Ranorex recommended way..." is there a reason why I should use your code or should not use my code?
Recommended only since you do not need string constants when using Ranorex adapters and the compiler will check that you do not have syntax errors.
Ciege wrote:Since my method is not recommended, does that mean that I am potentially setting myself up for a future failure? Is one way really better than the other?
If your code works, everything is ok and there is no downside to your method. Getting it to work initially is where the "recommended" method helps, since you have the compiler and code completion in order to get the attribute names correct.

Regards,
Alex
Ranorex Team
.
Image

anzacthecat
Posts: 31
Joined: Mon Jan 10, 2011 1:05 pm

Re: Web document caption

Post by anzacthecat » Tue Jun 07, 2011 11:15 am

Thanks, that solved the problem.