Getting Text from Parent element while Text in Child exists

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…

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” :wink:

Hi Sebastian,

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

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.

1 Like

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

1 Like