Evaluating XPath

Created by Akabot Support, Modified on Tue, 16 Dec, 2025 at 12:01 AM by Akabot Support

Table of Contents

  • Evaluating XPath
  • Specifying elements by text


1. Evaluating XPath

You can check whether the intended element is correctly specified by XPath in Chrome. Additionally, you can verify if the XPath you want to write in akaBot correctly specifies the intended element.

You can evaluate XPath using the "Console" in the "Developer Tools" built into Google Chrome. The notation for evaluating XPath in the "Console" is as follows:

$x('xpath')


Open the top page of the akaBot Portal in Chrome.

Press the "F12" key to open the "Developer Tools" and click the "Console" tab.


Let's evaluate the XPath //*[@id="custom-blocks"]/div/div/div[2]/a.
This XPath specifies the element surrounding the text "How to Use akaBot" on the top page of the akaBot Portal, particularly the blank space around it. (This is the XPath obtained in the "Basic XPath" section.)
Enter the following in the Console and press the "Enter" key:
javascript
Copy code
$x('//*[@id="custom-blocks"]/div/div/div[2]/a')


  1. The execution result will be displayed on the next line after entering the XPath. Click on it to expand.
  2. When you hover the mouse pointer over the expanded a element, the corresponding part of the element will be highlighted. Since the expected element (the blank space surrounding the text "How to Use akaBot") is highlighted, you can confirm that the XPath has been correctly written.

Note: If you want to open the "Developer Tools" from the browser menu, refer to the image below to display it.

2. Specifying Elements by Text

Sometimes, you might not know the value of the id attribute when specifying an element. Now, let's check how to specify the element of the text part of "How to Use akaBot."

When you want to specify an element that contains specific text, use the text() function, which evaluates the type of node, and the comparison operator =. The notation is //*[text()="How to Use akaBot"].

Enter the following in the Console to check whether the intended element is correctly specified:

javascript

Copy code

$x('//*[text()="How to Use akaBot"]')


  1. The execution result will be displayed. Click on it to expand.
  2. When you hover the mouse pointer over the expanded h3 element, the corresponding part of the element will be highlighted. Since the expected element (the text part of "How to Use akaBot") is highlighted, you can confirm that the XPath has been correctly written.

Since there is only one instance of the text "How to Use akaBot" on this page, the execution result is a single element. If there are multiple matching elements, the execution results will display multiple elements.

For example, if you execute $x('//*[text()]'), multiple results will be displayed.

The XPath $x('//*[text()="How to Use akaBot"]') specifies only the element with the text "How to Use akaBot" among the multiple elements returned by executing $x('//*[text()]').



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article