Home > Software design >  Excluding tags with links using Xpath
Excluding tags with links using Xpath

Time:12-21

I want to exclude all tags with links using xpath

<p/>...</p>
<p/>...</p>
....
<p/>
<strong/>
<a href="https://exapmle.com" rel="nofollow">Link</a>
 </strong>
</p>

I need to parse all tags excluding the last one which contains href

found some here Tried p[not(contains(@href,'example'))], but it doesn't work

CodePudding user response:

This XPath will give you all the p nodes not containing a child containing href attribute:

"//p[not(.//a[@href])]"

Also since you are using Selenium - XPath 2.0 is not relevant here since Selenium supports Xpath 1.0 only

CodePudding user response:

Maybe this one?

//p[descendant::a[not(contains(@href,'example'))]]

You are getting all the p elements which their a childs do not contain the href property with value example

Also this one can be valid for what you want:

//p[.//a[not(contains(@href,'example'))]]
  • Related