Why we need to find XPath?
For each Automation Engineer, finding XPath is one of the monotonous and boring tasks perhaps no one wants to kill their time on this and for new automation engineers, it’s the toughest task in beginning. Traditionally, we used DevTools and console for XPath finding and validation, these XPath are usually absolute and useless. To solve this problem one automation engineer developed wonderful utility which saves so much time. That tool is ChroPath. Here is the way to how to use Chropath.
What is ChroPath & How it makes finding XPath easy?
ChroPath generates unique relative XPath, absolute XPath, CSS selectors, link text and partial link text just by one click. ChroPath can also be used as Editor for selectors. It makes easy to write, edit, extract and evaluate XPath queries on any webpage. ChroPath also supports iframe, multi selectors generation, generate relative XPath with a custom attribute, automation script steps generation and many more.
How to install ChroPath?
- Search “ChroPath Chrome extension in Chome” and click on Browser
Or click to URL : https://chrome.google.com/webstore/detail/chropath/ljngjbnaijcbncmcnjfhigebomdlkcjo?hl=en
- Click on “Add TO CHROME”
- Once the extension is added, you get the ChroPath icon in the Chrome menu as shown below.
How to use ChroPath?
- Right-click on the web page, and then click Inspect.
- On the right side of the Elements tab, click on the ChroPath tab.
- To generate selectors, inspect element or click on any DOM node, it will generate the unique relative XPath/absolute XPath/CSS selector/linkText/partialLinkText.
- To evaluate XPath/CSS, type the XPath/CSS query and press enter key. As you enter, it will query in DOM for the relevant element/node. You can view the matching node(s) and nodes value as per their sequential occurrence. A green color outline appears around to highlight the first matching elements and rest in blue color on the web page.
- If you mouse hover on any matching node in the ChroPath tab, green/blue dashed outline will convert into dotted orange-red to highlight the corresponding element on the webpage.
- If the found element is not in a visible area on a webpage then mouse hover on found node in ChroPath panel will scroll that element in the visible area with a dotted orange-red outline.
- If the found element is not highlighted but visible then on mouse hover on the matching node on ChroPath tab it will highlight element with a dotted orange-red outline.
- copy the locators just by clicking on the copy icon.
- click on edit icon if you want to edit any locator.
Generate Relative XPath with attribute
- Click on the setting button which is available in the ChroPath tab.
- In the attribute name box, type your attribute value and hit enter.
- It will generate the relative XPath with the given attribute if that will be unique else it will try with other attributes and text or parent.
- If the given attribute is not there in the node then it will generate the unique relative XPath with some other attribute.
- Also for few attributes (id, class, name, and placeholder) sort cuts have been provided. If you don’t want to generate XPath with any of these attributes, just uncheck them.
Generate Automation code
- Click on the set driver command icon (+ icon, besides setting icon) in the ChroPath tab.
- Now when you will generate selectors, it will generate selectors with pre-command like driver.findElement(By.xpath(‘xpathValue’)) appended in selectors.
- You can also change this command. Like FindByXpath(‘xpathValue’). Just have the keyword ‘xpathValue’ in your command where you want to replace the selector value.
- Now just by clicking on the copy icon, you got full automation step.
- It will add the pre-command only when this is active if you don’t want to add pre-command click on the plus icon again.
Generate selectors in bulk along with label name
- Click on the record button in ChroPath tab.
- Now here just inspect all the elements or click on DOM node for which you want to generate the selectors.
- It will generate a selector along with the label name.
- You can copy, edit, delete any of the rows in the table.
- Label and selectors fields are editable, so you can directly edit them there itself.
- You can also export all the generated selectors, just by clicking the Export icon given in the table header in the ChroPath tab.
- At any point in time if you want to stop recording and go back to the default view, just click on the record button again. This will not remove your recorded selectors but if you will close the dev tool then you will lose them.
- Also, you can stop recording at any time just by clicking on ON/OFF button.
- Every time when you will open the dev tool and then ChroPath, it will be a fresh window.
Get selectors and editor both the options in single selector view
- If you want to work with any particular selector like Rel XPath only, then change the selectors drop down value to Rel XPath.
- Here you will get Rel XPath as in separate row like default view and editor box empty to use ChroPath as editor in the same time.
- Now ChroPath gives the colored relative xpath.
- Delete option in place of delete one by one.
Note: *Supports only those iframe which has the same src.
- If element inside iframe, then it will highlight first matching element in orange dotted outline.
- It will also add one ‘if..’ icon in input box of ChroPath tab to make it clear that element is inside iframe.
- If you want to verify your selector inside iframe then 1st inspect any element inside that iframe so that it get the DOM of iframe and then verify the selector.
- Again if you want to verify any selector for a element which is outside iframe then first inspect any element which is outside iframe so that it get the top DOM and then verify the selector.
Dynamic ID support
- To generate relative xpath without id, uncheck the checkbox there in relative xpath row.
- To generate relative xpath with id, select the checkbox.
- If you don’t want to generate selectors, turn off the button available in ChroPath tab.
- Turn on the button to enable ChroPath again.
- To use dark theme, go to devtools settings.
- Change the Theme from Light to Dark.
- For one selector only, change the dropdown value from selectors to rel XPath/abs Xpath/CSS sel in header.
- Tool will add xpath/css attribute to all the matching node(s) as per their sequential occurrence. For example, a matching node appearing second in the list will have xpath=2. And if verifying CSS then it will add css=2.
- Supports only those iframe which has the same src.
Hope above tutorial help you in adding “ChroPath” on browser and use it during Automation. ThoughtCoders highly recommend this tool for Automation engineer as it boost efficiency of Automation Engineer.
For more information, please contact us on firstname.lastname@example.org or visit our website www.thoughtcoders.com.