So here is the sample html doc:
<div id="div1">
<ul class="lists">
<li class="listItem1">
List content
<span class="span1">span text</span>
</li>
</ul>
</div>
I only want to extract "List content"
If I do this:
elementList = driver.find_element(By.XPATH, "/div/ul/li")
elementList.text
I get : List content span text
If I do this:
elementList = driver.find_element(By.XPATH, "/div/ul/li[1]")
I still get List content span text
What can I do to only get
"List content" without the span text
2
Answers
Try
text()
option, it will return the text present in theli
tagelementList = driver.find_element(By.XPATH, "//div/ul/li/text()")
OR
elementList = driver.find_element(By.XPATH, "normalize-space(//div/ul/li/text())")
This might be a little long winded, but I think it should do the trick.