<span class="cname"><em class="multiple">2017</em> Ford
</span>
<span class="cname">Toyota
</span>
I want to get only "FORD" and TOYOTA in span.
test.find_element_by_class_name('cname').text
return "2017 FORD" and "TOYOTA". So how can i get particular text of span?
Pure XPath solution:
//span[@class='cname']//text()[not(parent::em[@class='multiple'])]
And if you alse want to filter white-space-only text-nodes():
//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]
Both return text-nodes not an element. So Selenium will probably fail.
Take a look here: https://sqa.stackexchange.com/a/33097 on how to get a text-node().
Otherwise use this answer: https://stackoverflow.com/a/67518169/3710053
EDIT:
Another way to go is this XPath:
//span[@class='cname']
And then use this code python-example to get only direct text()-nodes.
EDIT 2
all_text = driver.find_element_by_xpath("//span[@class='cname']").text
child_text = driver.find_element_by_xpath("//span[@class='cname']/em[@class='multiple']").textparent_text = all_text.replace(child_text, '')