advance xpath

14
Advance Xpath Processing Suresh

Upload: suresh-g

Post on 24-Apr-2015

1.187 views

Category:

Technology


3 download

DESCRIPTION

Advance Xpath Processing

TRANSCRIPT

Page 1: Advance xpath

Advance Xpath Processing

Suresh

Page 2: Advance xpath

What is Xpath

XPath is a syntax used for selecting parts of an XML document

The way XPath describes paths to elements is similar to the way an operating system describes

paths to files

XPath is almost a small programming language; it has functions and expressions

XPath is a W3C standard

Page 3: Advance xpath

Html page

Page 4: Advance xpath

Using contains to search text

Page 5: Advance xpath

Using starts-with to search attribute value

/html/body/div/table[3]/tbody/tr/td

Page 6: Advance xpath

Using Operator

//div[contains(@class,'pagination')]//a[contains(.,'>') and not(contains(.,'|'))]

Page 7: Advance xpath

Using Functions

//td[contains(.,'Chapter')][position() =2] //td[contains(.,'Chapter')][2]

Page 8: Advance xpath

Starting from a given node, the self, preceding, following, ancestor, and descendant axes form a partition of all the nodes

Axes (outline View)

Page 9: Advance xpath

Axes (outline View)Self

Preceding

Page 10: Advance xpath

Axes (outline View)Following

Ancestor

Page 11: Advance xpath

Axes (outline View)

Descendant

Page 12: Advance xpath

Selecting using xpath

driver.findElement(By.xpath("//select/option[contains(.,'pc')]"))

driver.findElement(By.xpath("//input[contains(@id,'red') and @type='radio']")).click();

driver.findElement(By.xpath("//input[contains(@name,'vehicle') and contains(@value,'Nothing')]")).click();

Selecting from dropdown list

Selecting radio button

Selecting checkbox

Page 13: Advance xpath

Advantage of smart xpath processing

Maintenance is easy Debugging is easy Saves time and energy Reduces the documentation time

Test case to click first chapter driver.findElement(By.xpath(“/html/body/div/table[3]/tbody/tr/td”)).click(); or driver.findElement(By.xpath(“//td[contains(.,'Chapter')][1]”)).click();

Page 14: Advance xpath