Wednesday, January 29, 2014

Testing XPath in Google Chrome browser

Many times during Test Automation, we use XPath to match the required object/tag in the DOM. While working with XPath, I'm wondering is there anyway to test XPath in Google Chrome browser with highlighting the matched tag in browser. The answer is YES. We can test XPath in Google Chrome.

Follow these steps to test your xpath:

1. Open Developer Tools - When you're in Chrome (on the page where the object is appearing), press F12

2. Select Console tab - just press ESC key and you'll see extra pane appearing at bottom. This is where you can type commands to test XPath.

3. Use $x token. For example, enter following in the console windows $x("/html/body") and then press ENTER. It will select the body tag and the result tag will appear just below command you entered.

In case, the entered XPath is wrong, it won't return anything.

Bingo!


NOTE: Unlike Firefox, Chrome has an in-built "developer-tools" option!