advance xpath

Post on 24-Apr-2015

1.187 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Advance Xpath Processing

TRANSCRIPT

Advance Xpath Processing

Suresh

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

Html page

Using contains to search text

Using starts-with to search attribute value

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

Using Operator

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

Using Functions

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

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

Axes (outline View)

Axes (outline View)Self

Preceding

Axes (outline View)Following

Ancestor

Axes (outline View)

Descendant

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

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();

top related