Furkan DURMUŞ
Furkan DURMUŞ

Reputation: 39

How to use "not" attribute with "class name" in Xpath?

//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]

I need to remove text() in this code. Because when I use text() it becomes an object. But if I type ".text" at the end of my python code it turns to element.

I need an element not an object. So I need to rewrite "text()" from the code without any other changes, or change it from object to element.

Upvotes: 0

Views: 277

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66723

If you want to select the parent element of that text() you could just add /.. or /parent::* to the end of the XPath

//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]/..

or

//span[@class='cname']//text()[not(parent::em[@class='multiple']) and not(normalize-space()='')]/parent::*

Upvotes: 1

Related Questions