Skip to content


This page will go over all the different ways that xpath can be used and everything you need to know to successfully create your own xpath from scratch/

Below you will find an example of xpath:

//div[contains(@class, "skip-links")]//a//span[contains(text(),"Account")]

The xpath above is used to find the account link on a default magento 1 homepage, you can try for yourself by visiting this Magento 1 demo site

Xpath In Behat

Xpath in behat can be used to find a specific element of a website, by using xpath this can help limit the amount of results you get and be the difference in you tests passing of failing.

If you are using PHPStorm then this will make it easier to write and check your xpath.

When writing an xpath you will usually start from with in the website source code in the browser, while doing this it might be difficult to make sure everything is working correctly and to check for syntax errors.

The great thing about phpstorm is that you can create a scratch file dedicated to checking xpath. This will give you an indication of what you have done wrong straight away.

You can create this file by doing the following.

Double Tap Shift #opens search everywhere window
Type -> "New Scratch File"
Select XPATH from the list of languages




Need to add information on what each section of the xpath means