It's difficult. As far as webdriver is concerned, the text before and after the child <span>
is equally validly part of the text content; and it doesn't have methods to just return bits and pieces of the text content.
What I'd try is:
- Use a method to get the full inner html of the div.
- Use string manipulation to divide it up into three parts; before the
<span>
, the<span>
itself, and after the<span>
.
The first part is reasonably straightforward; see Get HTML Source of WebElement in Selenium WebDriver using Python for how to get the html source of a single element.
The second part is not too difficult either; it should be easy enough with python's string functions. It will get complicated, however, if the format of the inner text is more variable (i.e. not just text-span-text each time).
Good luck!