A check with xpath is failing.

I am using a check:

to test the textbox displayed on google page. This check is failing even though the xpath is correct. Could you please help me to figure out why the check is failing?
Here is the script for your reference:

class scala1 extends Simulation {
// your code starts here
val scn = scenario(“My scenario”)
.exec(http(“My Page”)

// your code ends here

You didn’t describe how it fails…

I suspect your problem is that the response is not valid xml (xhtml) but regular html.
Don’t get confused by browser plugins: they work on the page DOM, not on the html page.

Anyway, with Gatling, you can only use xpath with valid xml.
For html, I suggest you use css selectors: https://github.com/excilys/gatling/wiki/Checks#css

Beware: Gatling works on the HTTP response body, not on the page as it would be resolved by a browser (no javascript).

Consider example of page http://www.google.co.in
I installed postman rest http client to view response received on specifying a URL.
In the postman rest client I specified URL http://www.google.co.in with get action.
In the xml that I got in response, following tag is present:

Google I specified a check as follows in my Gatling script: .check(xpath("//title[text()='Google']"))

The check fails - The report file index.html shows the request as failed.


Again, as Stéphane previously stated, HTML is not valid XML.And Google doesn’t give you back XML, but HTML. Therefore you can’t use XPath on HTML pages, as XML only works on XML.
As Stéphane suggested, CSS Selectors are the way to go to match things in a HTML page.
Sidenote : Even if your HTML page was valid XML, as XHTML is, using XPath would still be way more painful than CSS selectors to use.



Understood, but an example will get me going.
Can you give example of a xpath check which is checking any UI element on Google page, please?

Can you give example of a xpath check which is checking any UI element on Google page, please?

Once again, you can NOT use xpath with Gatling for regular HTML pages. Just forget about it.
You can use xpath for SOAP, XML-RPC, and any other XML based protocol.

There are no examples of xpath checks on the Google homepage, because xpath works on xml, and HTML web pages aren’t xml. Stéphane linked to the Gatling documentation on using CSS checks, and there are examples of CSS selectors here (linked in the documentation): http://jodd.org/doc/csselly/

An exemple if you want to match the search text box on Google :

Using your preferred browser’s dev tools, “inspect” the text box.
You’ll see that’s an , for which the id is “gbqfq” and the class is “gbqfif”.
You can match the text box using either the id, the selector would be “#gbqfq”, or the class and the selector would be “.gbqfif”.
With Gatling APIs, you would match the text box with .check(css(“#gbqfq”)) or .check(css(“.gbqfif”).

Got it ?

I tried check
The report is showing that the request failed.
Here are my scripts:
-----------------script name: gsw1-----------------
package practice.archana
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
//import Headers._
import akka.util.duration._
import bootstrap._

object gsw1 {

val scn = scenario(“Google page”)
http(“Google homepage”)

-----------------script name: gsw2-------------------------
package practice.archana

import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._

class gsw2 extends Simulation {

val httpConf = httpConfig.baseURL(“http://www.goole.co.in”).disableFollowRedirect


Hi Stephane,

Can you give me an example of how you could use css selector to extract something like viewstate: