Getting text form element except child elements

27 views
Skip to first unread message

mef

unread,
Jul 3, 2013, 5:34:18 AM7/3/13
to page-...@googlegroups.com
Hi, everyone.

How to get text from element except element's childs?

Here the code

<span class="bi-text">
  "text"
  <div class="bi-subinfo">
    "another text"
  </div>
</span>

span_element(class: 'bi-text').text returning me the String "text\nanother text"
I need to get text from that span except child div element

Dane Andersen

unread,
Jul 3, 2013, 8:06:30 AM7/3/13
to page-...@googlegroups.com
I don't know if you have control over the code at all. Likely the easiest approach would be to put some sort of div around the first text, and then you could address it directly. If that isn't an option, the easiest way would be to slice! the text out since you can get the inner text to remove easily.

mef

unread,
Jul 3, 2013, 10:48:06 PM7/3/13
to page-...@googlegroups.com
Thanks, for reply.

I think slice would work correctly. I'm also found another way: using "string1\nstring2".lines[0].to_s.chomp return "string1".

среда, 3 июля 2013 г., 19:06:30 UTC+7 пользователь Dane Andersen написал:
Reply all
Reply to author
Forward
0 new messages