Xpath Element in Katalon Recorder (web extension) does not Function in Katalon Studio

When recording using the Katalon Recorder (web extension), I can play the test using the recorder, but when I export to Katalon Studio code, I run into problems with Xpath Identification:

PROBLEM ONE:
This code won’t find the object:

selenium.click(“xpath=(.//*[normalize-space(text()) and normalize-space(.)=‘Commercial Auto’])[1]/following::span[3]”)

despite having this declared at the top of the test:

def driver = DriverFactory.getWebDriver()
String baseUrl = ‘valid URL’
selenium = new WebDriverBackedSelenium(driver, baseUrl)

Receive this error:
Element xpath=(.//*[normalize-space(text(> )) and normalize-space(.)=‘Commercial Auto’])[1]/following::span[3] not found

Cannot find an element with the xpath: (.//*[normalize-space(text()) and normalize-space(.)=‘Commercial Auto’])[1]/following::span[3]
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html

Adding the Element to the Object Repository with

Blockquote

xpath equals: //span[contains(@text,‘Commercial Auto’)]

Also results in the same problem.

Did you run the test on the same browser for KR and KS?

Please try inserting Thread.sleep(5000) before the step and see if timing is the root cause.

Same browser - Chrome in both tests.
Have a standard wait time of 45 seconds currently for project as we’re building out scripts for a code base project.

Please try validating the XPath using F12 tool and let us know the result.

Also, Please try removing the prefix xpath= and execute the test again to see if it works.

1 Like

Sometimes Katalon just goes way to fast. Therefore you need to set up wait intervals.

removing the xpath= helped

Now I receive the error
Reason: com.thoughtworks.selenium.SeleniumException: Element (.//*[normalize-space(text()) and normalize-space(.)=‘Commercial Auto’])[1]/following::span[3] not found

But again — the question is why does that work in the recorder, but not in Katalon studio ???

Thanks for so many responses already

same issue occurs regardless of delays

Did you? What was the result?

Hi @gxwheel

It’s very important that you use Inspection Tool on chrome ( or your browser ) to verify if the xpath works.

Also, one of the reason why you should generate the script using Katalon Studio’s Web Recorder is that Katalon automatically generated for you multiple locators from which you can choose (otherwise you’d have to write the xpaths yourself, which is fine but there are cases when the generated ones work really well ).

tested with Xpath search tools now. Here is the result:

  1. Katalon Recorder >> Export to Katalon Studio version: selenium.click(“xpath=(.//*[normalize-space(text()) and normalize-space(.)=‘Commercial Auto’])[1]/following::span[3]”)
  2. Change to code (remove “xpath=”): selenium.click("(.//*[normalize-space(text()) and normalize-space(.)=‘Commercial Auto’])[1]/following::span[3]")
  3. Results:
    3a) fails in script
    3b) fails in xpath search in Chrome/Firefox
  4. change xpath to the following: //span[contains(text(),‘Commercial Auto’)]"
    4a) passes in script
    4b) passes in xpath search in Chrome/Firefox

I used the web recorder and it’s giving me code that has to be adjusted in multiple ways before being functional. That was the point of my question.

Hi @gxwheel

So it means the XPath isn’t correct, therefore it failed in the Inspection tool of Chrome. As to why it’s running on Katalon Recorder and not in Katalon Studio, it’s hard to say, we would need screenshots of the web page running on your own browser versus running on a new Web driver instance that Katalon Studio spawns, along with the HTML structure for both cases.

One thing comes to mind is perhaps your web page has some cached information that are used to change the underlying HTML in some ways. Since Katalon Recorder ( the web extension ) plays back in your own browser (with cache), the target element may be different than when Katalon Studio plays back in a new Web Driver instance (without cache).

Final thought:

Are you certain you are using Katalon Studio’s Web Recorder ? It is a different thing from Katalon Recorder (Web Extension).

1 Like

I was using the Katalon Recorder (a web extension) and have updated the title.
The Katalon Studio Web Recorder has a slightly different name, so I didn’t realize the confusion until now.

@gxwheel

Glad I could be of help. Did you try to use the Web Recorder to record the test case and re-run if the problem still persists ?