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.
Getting the innertext of a DIV
Re: Getting the innertext of a DIV
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.
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...
Ciege...
Re: Getting the innertext of a DIV
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
I see what you are saying now. Sorry for the confusion.
Unfortunately, I cannot answer that question for you.
Unfortunately, I cannot answer that question for you.
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...
Ciege...
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Getting the innertext of a DIV
Hi,
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
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 was able to get inner text of a DIV even if it was for a sub object
If there is an element or more elements between like in this case:I just expected the DIV object's inner text to be the "inner text"
<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
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.
Aracknid.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Getting the innertext of a DIV
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
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
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Getting the innertext of a DIV
Hi,
To get the whole InnerText of an element you can use regular expressions and the following method:
Markus
Ranorex Support Team
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