I have simple xpath
/products/product[contains(categorie,'Kinderwagens')]
It works but now how do I filter on multiple categorie values
like
/products/product[contains(categorie,'Kinderwagens')] +
/products/product[contains(categorie,'Kinderwagens')]
$xml->xpath("(//person)[firstname[contains(., 'Kerr')]]"); then it works fine.
contains() in Selenium is a function within Xpath expression which is used to search for the web elements that contain a particular text. We can extract all the elements that match the given text value using the XPath contains() function throughout the webpage.
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
The | character denotes the XPath union operator. You can use the union operator in any case when you want the union of the nodes selected by several XPath expressions to be returned.
Will this work?
/products/product[contains(categorie,'Kinderwagens') or contains(categorie,'Wonderwagens')]
There is a similar question here
Do you really want contains()? Very often, people use contains() to test whether a node contains a value when they should be using "=". The difference is that if the categorie element has the string value 'Kinderwagens', then categorie = 'wagens'
is false but contains(categorie, 'wagens')
is true.
If you actually intended '=', then in XPath 2.0 you can write [categorie = ('Kinderwagens', 'Wonderwagens')]
. If you're still using XPath 1.0, you need two separate comparisons with an 'or'.
There are many ways:
//*[contains(text(), 'Kinderwagens') or contains(text(), 'Kinderwagens')]
//product[contains(text(), 'Kinderwagens') or contains(text(), 'Kinderwagens')]
//products/product[contains(text(), 'Kinderwagens') or contains(text(), 'Kinderwagens')]
//products/product[contains(categorie, 'Kinderwagens') or contains(categorie, 'Kinderwagens')]
Note: | (Bitwise OR) operator don't be use
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With