'XPath: counting elements excluding another elements from count

I need to count all the elements that includes text 'Automation' but excluding the span[@class = "hot"] elements from the count.

The site with a html code is : https://www.epam.com/careers/job-listings?sort=best_match&query=&department=Software+Test+Engineering&city=all&country=all

I can count every search result by:

count(//li[contains(@class, 'search-result-item')])

and it works as needed but how should I include only the elements with

//a[contains(text(), 'Automation')] 

and exclude the search result elements that has

span[@class = "hot"]


Solution 1:[1]

Selects li that does not have a span with class="hot" and from there select your a link.

It should be something like:

//li[not(.//span[@class="hot"])]//a[contains(text(), 'Automation')]

You could also add other restraints for li to have a certain class and/or from certain section.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lauda