Saturday 30 April 2016

XPATH Functions




1) Node Set Function
2) String Function
3) Boolean Function
4) Number Function




1) Node Set Function

-> last()

Identify the last item of current node set.

Ex : https://www.google.co.in

//div[@id='sfdiv']//input[last()]  -> its identify last input tag



-> position()

Identify the item as per the postion. Position value start from 14.

Ex : https://www.google.co.in

//div[@id='sfdiv']//input[position()=1]  -> its identify first input tag



-> count()

Its count the number of element from context node.


Ex : https://www.google.co.in

count(//div[@id='sfdiv']//input)  -> o/p=3, Return total number of input element.



-> local-name()


Instead of element tag(//div)) we can use local-name() (local-name()='div')

Ex : https://www.google.co.in

local-name(//div[@id='sfdiv']//input)

//*[local-name()='div' and starts-with(@id,'sfdiv')]//input



-> id()

Its returns elements which ID specified in code


Ex : https://www.google.co.in

id("sfdiv")/div//input  -> o/p=3, Identify all 3 input tag.


The xpath id("sfdiv")/div//input  and //div[@id='sfdiv']//input both are same.


**********************************************************************



2) String Functions


-> String()

we can identify the object by using text. Both Text() and String() are same.


Ex : https://www.google.co.in

//div[@id='gbw']//a[String()='Gmail']

//div[@id='gbw']//a[text()='Gmail']

Both are same.


o/p identify the object which having the GMAIL text.



-> Concat()

Its Used to concatenate the two string


Ex : https://www.google.co.in


concat(//div[@id='gbw']//a[text()],' ',//div[@id='gbw']//a[text()])

O/p String: Gmail Gmail

concat(//div[@id='gbw']//a[text()],' ',//div[@id='gbw']//div[2]//a[text()])


O/p String: Gmail Images




-> starts-with()


Its identify the object by using text which starts given string.


Ex : https://www.google.co.in

//*[local-name()='div' and starts-with(@id,'sfdiv')]//input


o/p identify all three objects.



-> Contains()

Its identify the object which contains the text

Ex: https://www.google.co.in


//div[contains(id,'sfdiv']//input

o/p identify all three objects.



-> substring-before()

Its retrives the substring of first argument

Ex : https://www.google.co.in

substring-before(//div[@id='gbw']//a[text()],'a')

o/p  String: il


we can use this xpath like below for identify the object

//div[@id='gbw']//a[contains(.,substring-before(//div[@id='gbw']//a[text()],'a'))]





-> substring-after()

Its retrives the substring of first argument

substring-after(//div[@id='gbw']//a[text()],'a')


O/P     String: il


we can use this xpath like below for identify the object

//div[@id='gbw']//a[contains(.,substring-after(//div[@id='gbw']//a[text()],'a'))]



*******************************************************************8


3) Boolean Function


-> Boolean boolean(object)

Converts the argument to a Boolean value.

Example - boolean(/journal/article/author/last[.='Jones'])



-> Boolean not(boolean)

Negates the boolean value.

Example - not(/journal/article/author/last[.='Jones'])


***************************************************


4) Number Function


Will update shortly




https://docs.oracle.com/cd/E35413_01/doc.722/e35419/dev_xpath_functions.htm#autoId19

No comments:

Post a Comment