Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Tuesday, February 21, 2012

How to add a Xpath Assertion in JMeter

As i've mentioned in my earlier posts about how assertions can be of help in validating the right response code

Xpath Assertion eases life when we have to validate if an object exists.

For ex:

Let's again take a shopping cart example.

1.Search for an item
2.Add selected item to shopping cart > now we want to verify if the Add cart button is available on the page.

Therefore we need to add a xpath assertion.

Below screen shot should give a clear idea & how an expression is built.

Let's have a closer look at the Xpath Assertion.

Add a xpath Assertion :

1. Right Click on the HTTP Sampler > Assertions > Xpath Assertions.

Once you'ev added the Xpath Assertion, now we have to add appropriate values so that we can assert object or value.

1. Give a name to Xpath Assertion just like i have given not necessarily same.

2. XML Parsing Options - Check the Checkbox's against "Use Tidy(tolerant parser) & Quiet".

3. Xpath Assertion - contract the xpath & pass the xpath string within the Xpath Assertion.

For ex : I am validating to see if the button with id "bestAvailableTickets_LookForTicketsButton"" exists on that page.

I have left the "True if nothing matches" as unchecked as i want it to match.
automationwithselenium.blogspot.com-Google pagerank and Worth


  1. I did but it throwing me an error can u plz help me

    1. @Snigdha

      Please accept my apologies for not returning back to you on time
      post your error messages & what you are trying to achieve , which would help in nailing down your issue

  2. Hi,
    I am praveen varma.

    I have recorded some script and and added the xpath assertion to find out the whether the login button exists in my web application.
    But i got some error after viewing the results.I will post the result here , so can u explain me regarding the error?

    Result :-

    Xath used in the XPath Assertion :- .//*[@id='body']/div/center/form/table/tbody/tr[4]/td/input

    Error msg displayed as:-
    ForgotPassword Link
    XPath Assertion : SAXException: The element type "link" must be terminated by the matching end-tag "/link".

  3. Can u share ay videos regarding the xpath,compare and xml, xml schema assertions in JMter?

    I am waiting for your favourable reply.

    1. @Praveen Varma .. apologies for not being active, if you haven't found answers please feel free to message me

    2. This comment has been removed by the author.