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