I am using Selenium Protractor and want to select all elements from the following list except one that contains text \"Cat\" and then perform some operations on the remainin
You can create a List selecting all the elements except one that contains text Cat using the following Locator Strategy:
xpath:
//div[@class='mainDiv']//div[@class='childDiv'][not(contains(.,'Cat'))]
When using Selenium and css-selectors:
The :contains pseudo-class isn't in the CSS Spec and is not supported by either Firefox or Chrome (even outside WebDriver). You can find a detailed discussion in selenium.common.exceptions.InvalidSelectorException with “span:contains('string')”
However, if the elements always appears within the DOM Tree in a specific order, e.g. Cat always at the forth child, you can also use:
cssSelector:
div.mainDiv div.childDiv:not(:nth-child(4))
You can find a couple of relevant discussions in: