# Getting Text from Parent element while Text in Child exists

**URL:** <https://forum.robotframework.org/t/getting-text-from-parent-element-while-text-in-child-exists/3673>\
**Category:** Browser\
**Created:** [22 April 2022 14:26 UTC](https://forum.robotframework.org/t/getting-text-from-parent-element-while-text-in-child-exists/3673 "2022-04-22T14:26:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vejitta](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/vejitta/32/1451_2.png) [@Vejitta](https://forum.robotframework.org/u/Vejitta)\
**Post date:** [22 April 2022 14:26 UTC](https://forum.robotframework.org/t/getting-text-from-parent-element-while-text-in-child-exists/3673/1 "2022-04-22T14:26:10Z")

</div>

I’m facing some issue, which I refuse to believe can’t be handled by Browser library.

The structure of the page is something like that:

```
<span1>
    <span2>text</span2>
another text
</span2>

```

Now…  
“GET TEXT //span1” retrieves _textanothertext_ which is not good.  
I was trying to use GET PROPERTY but properties which store _another text_ value are not found by Browser (i.e. ChildNodes.NodeValue) or maybe I’m using it wrong.

I feel like I’m missing something really simple here…

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [27 October 2022 23:24 UTC](https://forum.robotframework.org/t/getting-text-from-parent-element-while-text-in-child-exists/3673/2 "2022-10-27T23:24:42Z")

</div>

I’ve only just started trying out browser library if I was to be honest from moving from seleniumlibrary, but from what I understand there’s no way of getting the text without that second span text value in this instance with Get Text and it’s acting as it should (could be wrong), it was pretty fun to play around with the Get Text and Get Property.

But what you could do in the mean time is:  
` ${el} Get Element "insert_your_selector"`  
` ${value} Evaluate JavaScript ${el} (elem) => elem.firstChild.textContent`  
or  
`${value} Evaluate JavaScript ${el} (elem) => elem.firstChild.nextSibling.textContent`

Your example “something like that” 😉

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [28 October 2022 05:43 UTC](https://forum.robotframework.org/t/getting-text-from-parent-element-while-text-in-child-exists/3673/3 "2022-10-28T05:43:21Z")

</div>

Hi Sebastian,

Let’s take Browser library and Robot Framework out of the equation and see what that xpath produces on that html:

> **[XPath online real-time tester, evaluator and generator for XML & HTML](http://xpather.com/yzsA6B8U)**
>
> This most user-friendly online tool enables you to interactively and secretly query XML/HTML documents using XPath 2.0. It can generate queries for you too!

As you can see this is the same result, so I don’t think it’s a Browser library issue, perhaps try an xpath like `//span1/text()`

Dave.

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [28 October 2022 09:00 UTC](https://forum.robotframework.org/t/getting-text-from-parent-element-while-text-in-child-exists/3673/4 "2022-10-28T09:00:16Z")

</div>

Aha @damies13 I was so focused in on the library to oppose to the selector here!
