Page 1 of 1

Getting the innertext of a DIV

Posted: Tue Aug 16, 2011 6:27 pm
by Aracknid
I'm porting my code from an older automation to to VS 2010 using the Ranorex API.

In my old code using their DIV tag objects, I was able to get inner text of a DIV even if it was for a sub object, like an anchor or span within it.

Using Ranorex, I have a DIV object, but its inner text is nothing (using the Spy tool or programmatically).

Is this a bug or by design?

Here's an example of what I'm seeing. My treeview for my app is on the left. Spy on top. You can see the DIV has 3 child object, one is a Span. The span has the text value "1". I need to use innertext of the DIV to see the Spans value.
treeview.JPG

Re: Getting the innertext of a DIV

Posted: Tue Aug 16, 2011 7:09 pm
by Ciege
If you have a valid element to your DIV object, and the Span property holds the data you want, then all you need to do is query the Span property of the element for its data.

Re: Getting the innertext of a DIV

Posted: Tue Aug 16, 2011 7:19 pm
by Aracknid
I realize that it's possible to do what you suggest. It's just that it is different than another tool I was using. I just expected the DIV object's inner text to be the "inner text", which turns out in my case to be the value of a span with it. But it is not. So is this a bug?

Re: Getting the innertext of a DIV

Posted: Tue Aug 16, 2011 7:27 pm
by Ciege
I see what you are saying now. Sorry for the confusion.
Unfortunately, I cannot answer that question for you.

Re: Getting the innertext of a DIV

Posted: Wed Aug 17, 2011 9:59 am
by Support Team
Hi,
I was able to get inner text of a DIV even if it was for a sub object
With Ranorex it is able to identify sub objects like the <span> element, so if there is a <span> element in your HTML code Ranorex will show it.
I just expected the DIV object's inner text to be the "inner text"
If there is an element or more elements between like in this case:
<div style="color:#00FF00">
  <h3>This is <span style="color:blue">A</span>
a header</h3>
  <p>This is a paragraph.</p>
</div>
Ranorex will recognize the text as the InnerText of the corresponding HTML element. In this case the InnerText of the <h3> tag is "This is a header", the InnerText of the <span> tag is "A" and the InnerText of the <p> tag is "This is a paragraph" and this is perfectly right.
So if there is a <span> element in your DIV tag and the text is written between this <span> tag then everything works as expected.

Regards,
Markus
Ranorex Support Team

Re: Getting the innertext of a DIV

Posted: Wed Aug 17, 2011 2:10 pm
by Aracknid
Well then there is a bug. Look at my screen shot and scroll to the bottom right of the image. You can see the DIV's inner text is blank, even though in the DIV there is a span.

Aracknid.

Re: Getting the innertext of a DIV

Posted: Wed Aug 17, 2011 2:28 pm
by Support Team
Hi,

I have seen your screen shot but I didn't see that their is a bug, so have you carefully read my post?
In my example there is also no InnerText property for the DIV element, but it is perfectly right.

Regards,
Markus
Ranorex Support Team

Re: Getting the innertext of a DIV

Posted: Fri Mar 23, 2012 11:41 am
by Support Team
Hi,

To get the whole InnerText of an element you can use regular expressions and the following method:
var divTagMydiv = repo.WebDocument.YourElement;
      String pureInnerText;
      pureInnerText= Regex.Replace(divTagMydiv.GetInnerHtml(), "<.*?>", string.Empty);
      Report.Info("PureInnerText: "+pureInnerText);
Regards,
Markus
Ranorex Support Team