I'm currently working on HMI tests. For one of those tests, i would like to get some text on a page to use it later.
The structure of the HTML code is like so :
<span class="class1">
The text I want to get
<span class="class2">
<span class="class3">1</span>
<i class="class4">
::before
</i>
</span>
</span>
The text i would like to get is in the span with class="class1"
. In order to do that, i have this :
text_i_want = self.driver.find_element_by_css_selector('span.class1').text
The output i have however is The text I want to get\n1
. I would like to get rid of this \n1 in my string, and to do that, I used this :
text_i_want = text_i_want.split("\\")[0]
However, the output is still The text I want to get\n1
. Plus, here are 2 important points:
- The argument is
"\\"
, because if there is only one backslash, i get aSyntaxError: EOL while scanning string literal
- I tried
print(repr(text_i_want))
to see if the string i was getting in output was different from what I saw on the console, but it's still the same.
Do you guys know how to solve this ?
Note
I tried the solutions exposed here : Split a string by backslash in python. It didn't work for some reasons ..