In the following example:
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
text1
<br>
<img>
<br>
text2
</td>
</tr>
When I try to get the text in the 5th td like so:
something = elem.find_element_by_xpath('./td[5]').text
I get both texts in the same variable. I can split them but I was wondering if I can somehow get them in individual variables so I don't bother with a split. However when I try something like this:
something = elem.find_element_by_xpath('./td[5]/text()[1]')
I get the following error message:
InvalidSelectorException: invalid selector:
The result of the xpath expression "./td[5]/text()[1]" is: [object Text].
It should be an element.
Can I get around this error somehow?
find_elementmust be Element Node, your/td[5]/text()[1]will return a Text Node, this why you get the error. For What's Element/ Text Node, you can read HTML DOM document, for node in DOM Tree, it has 3 types, Element and Text is two types of the 3 types.