Page 1 of 1

Web document caption

Posted: Fri Jun 03, 2011 12:08 pm
by anzacthecat
How can I find out what the caption of the current Web Document is?

Re: Web document caption

Posted: Fri Jun 03, 2011 3:59 pm
by Ciege
While using a valid DOM object get the caption property of the element.

Code: Select all

string strCaption = myDom.Element.GetAttributeValue("Caption").ToString();

Re: Web document caption

Posted: Mon Jun 06, 2011 2:47 pm
by Support Team
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

Re: Web document caption

Posted: Mon Jun 06, 2011 3:47 pm
by Ciege
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!

Re: Web document caption

Posted: Mon Jun 06, 2011 3:56 pm
by Support Team
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

Re: Web document caption

Posted: Tue Jun 07, 2011 11:15 am
by anzacthecat
Thanks, that solved the problem.