18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
How to record randomly generated ids using Sahi Script
Hi all,
I want to click on a div element having a description and randomly generated ID. Recorded script works on playback , however on a different project it fails since the ID generated is random.
Could you please assist ?
I want to click on a div element having a description and randomly generated ID. Recorded script works on playback , however on a different project it fails since the ID generated is random.
Could you please assist ?
Best Answer
-
Hi divya,
Have you tried using regular expression?
_click(_div("/Ethernet Lite Port | NCO-.*/"))
Let us know if it works.
Answers
Does the div element have any attribute that is consistent over different projects and isn't a randomly generated value?
Regards,
Pratyush
Below is the div element code. As you can see below , the NCO - ### gets changed for different projects and also the values for the characteristics IP Variant , Port Speed , NTU Mode etc)
_click(_div("Ethernet Lite Port | NCO-02271283IP Variant: IPv4 Port Speed: 32K NTU Mode: EFM Order Type: New Customer Required Date: 04/02/2014"));
Is there any way to click on this div element by identifying just with the description value Ethernet Lite Port as other values seem to differ with the projects.
Still I am facing the same issue. Could you please assist ?
As Pratyush mentioned, there must be some element which does not change,
Go to Developer tools on your browser, and identify the above element using inspect button and check out the styles/properties of this "div" element and u might find some attributes to identify it.
(Also you can try with something like this according to DOM structure of you application- _click(_div(0,_near("")))
If not try to refer this element with reference to some other element using _near/_under.
If still nothing works, you can try using xpath as last option.(sahi has api's, _byXpath()).
I was able to click on the div element using _under api.