XPath 2.0 updates and workarounds

When working with XPath 2.0, expressions with the contains() function that include a function that may return multiple results as a parameter will result in the following error:

ERROR - Failed to evaluate XPath expression:net.sf.saxon.trans.XPathException: A sequence of more than one item is not allowed as the first argument of contains() ("", "", ...)

Copy

Example

//*[contains(text(),'Tom Waits')]

Workaround

You can avoid this error by using one of the following options.

Option 1: Isolate the text function and then get the object.

Copy
***For Perfecto Framework use the following***
//text()[contains(.,'Tom Waits')]/parent::*
***For Appium Framework use the following***
//@text[contains(.,'Tom Waits')]/parent::*         **Note if the string is under 'label' attribute replace 'text' with 'label' 

or

Copy
***For Perfecto Framework use the following***
//*[text()[contains(.,'ABC')]]
***For Appium Framework use the following***
//*[@text[contains(.,'ABC')]]            **Note if the string is under 'label' attribute replace 'text' with 'label' 

Option 2: Replace the '*' with the expected element name.

Copy
***For Perfecto Framework use the following***
//actor[contains(text(),'Liam Nelson')]
***For Appium Framework use the following***
//actor[contains(@text,'Liam Nelson')]        **Note if the string is under 'label' attribute replace 'text' with 'label'