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.
DOM load from file & access via DOM API on the server side - possible?
Hi,
Can I access a html file, read from disk into a DOM representation, from sahi scripts, on the SERVER side?
It's easy to do on the client side.
But we need to compare innerHtml content of the given html elements with given id between TWO html-files DUMPED via browser-side DOM API earlier - that's our tests' business logic specific.
Now we use javascript's regexp API and sahi's _readFile API to filter out and compare two html files.
But we need to find out html elements in the file dumped, by their html 'id' or 'name' attribute values - and compare these innerHtml parts.
Is it possible in Sahi?
Can I access a html file, read from disk into a DOM representation, from sahi scripts, on the SERVER side?
It's easy to do on the client side.
But we need to compare innerHtml content of the given html elements with given id between TWO html-files DUMPED via browser-side DOM API earlier - that's our tests' business logic specific.
Now we use javascript's regexp API and sahi's _readFile API to filter out and compare two html files.
But we need to find out html elements in the file dumped, by their html 'id' or 'name' attribute values - and compare these innerHtml parts.
Is it possible in Sahi?
Comments
The trick is to load the two files into the DOM.
One possible solution:
1) Create an html file with two divs with ids "leftDiv" and "rightDiv"
2) navigate to that file, and then do this:
Now all elements will be available in the dom. To differentiate elements of the same id, use
_textbox("myId", _in(_div("leftDiv")))
vs
_textbox("myId", _in(_div("rightDiv")))
Hope that helps.
Regards,
Narayan
Thank you, that does help. One question - as I guess - please confirm - is html comparision being made by Browser DOM engine? If it is, that's fine.
I've tried your trick - it seems to work, but one bad thing - browser's DOM engine does RENDER DOM-html to be compared. It's too slow...
If you will write a DOM-from-file compare function as _sahi call, try not to use browser's dom engine, but something that does not render DOM while in compare.
As I suppose for our purposes, I will try to call external JScript-scripts under Windows Host Scripting subsystem (as Windows XP professional distrib. and later contains Windows Host Scripting).
May you advise another appoach?
Unless the HTML is huge, it should not be very slow. After all, it is just twice the elements as the original page. Windows Scripting Host will not help here. It can execute JScript, not render HTML.
Regards,
Narayan