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.
_spandiv and simulate BACK button
Hi all,
It is my first post since I have downloaded Sahi yesterday.
It is a very good and powerful tool.
Thanks for making that open source.
I would have 2 questions for which I can not find the answer in the forum, unless I have missed it.
The first one is regarding the BACK button. I am currently writing a script to enroll students and once the application is submitted, the expected result could be rejected or accepted.
I had a look at the source code for the resulting page when it fails and the "sorry" reject string is part of a span.
So I used the _spandiv(text) to check whether or not it has been rejected.
However I am not quite sure on how to use it. I use it in a while loop such as:
while (_condition(_spandiv("Sorry") == null)
{
go back
resubmitted
}
The real behaviour of the code should be that if the string Sorry is found in a span, it should go back and resubmit the application.
My understanding of _spandiv is that it should return null if the text is not found but it seems that it is working the other way round.
My initial script was therefore
while (_condition(_spandiv("Sorry") != null)
{
go back
resubmitted
}
But it seems that it will never execute the content of the while loop. But if I change it to == null then it will execute it.
Any suggestion?
Unless I am using it the wrong way !
The second question is related to the same script and the go back in the while loop.
If the application is rejected, the actual user press the BACK button on internet explorer and resubmit the application. I mention the it is the BACK button from the web browser and not a back button in the web page.
I would like to know how this can be simulated in the script
At the moment, my solution is to use the _navigate but the problem is that it will go back 2 pages before instead of the previous one. Both pages have the same URL.
I would appreciate if someone could guide me as I am new to Sahi and because of the tight schedule, I have to learn Sahi on the go.
Thanks again
It is my first post since I have downloaded Sahi yesterday.
It is a very good and powerful tool.
Thanks for making that open source.
I would have 2 questions for which I can not find the answer in the forum, unless I have missed it.
The first one is regarding the BACK button. I am currently writing a script to enroll students and once the application is submitted, the expected result could be rejected or accepted.
I had a look at the source code for the resulting page when it fails and the "sorry" reject string is part of a span.
So I used the _spandiv(text) to check whether or not it has been rejected.
However I am not quite sure on how to use it. I use it in a while loop such as:
while (_condition(_spandiv("Sorry") == null)
{
go back
resubmitted
}
The real behaviour of the code should be that if the string Sorry is found in a span, it should go back and resubmit the application.
My understanding of _spandiv is that it should return null if the text is not found but it seems that it is working the other way round.
My initial script was therefore
while (_condition(_spandiv("Sorry") != null)
{
go back
resubmitted
}
But it seems that it will never execute the content of the while loop. But if I change it to == null then it will execute it.
Any suggestion?
Unless I am using it the wrong way !
The second question is related to the same script and the go back in the while loop.
If the application is rejected, the actual user press the BACK button on internet explorer and resubmit the application. I mention the it is the BACK button from the web browser and not a back button in the web page.
I would like to know how this can be simulated in the script
At the moment, my solution is to use the _navigate but the problem is that it will go back 2 pages before instead of the previous one. Both pages have the same URL.
I would appreciate if someone could guide me as I am new to Sahi and because of the tight schedule, I have to learn Sahi on the go.
Thanks again
Comments
Your initial script was right. But I think the span saying Sorry was always on the page and it is just being shown or hidden based on the result.
Could you check if the "Sorry" span is in the code even when the resulting page had succeeded?
If it is there, you could use
while (_condition(_style(_spandiv("Sorry"), "display") == "block")){
}
Part 2:
Sahi does not support the browser back button right now.
You could call _call(history.back()), but I know that Sahi does not work properly after that.
_navigateTo() is your best bet.
It is hard to check when the page succeeded because it never happens.
What I mean is that the script is designed to enroll students and press submit until it is successful. However there are a limited number of allocated seats for those students and you can get a success if you happen to submit the form at the right time. There is a time slot basically from 8am to 5pm where the website will accept the students.
Outside this time frame, the form is always rejected and because I work on the script after 5pm, I can not get a success page.
Hence I can not check on a success page whether or not it is hidden.
In the case it is not hidden, what do you think the best solution should be?
As mentioned in the previous post, if I write the original script with the != null, why does it not work when the page fails and I have Sorry displayed on the screen?
Any suggestion?
That would be much appreciated.
In the meantime, I will try your suggestion.
Is it possible with Sahi to save a web page on a PC then open this page locally and use sahi controller on this local page?
My idea is that I would like to save the page when it is rejected, then edit the source code, change the string in the span to something other than Sorry and then test the script.
The script will only do the while loop but nothing inside the loop.
Just a test to see if something other than sorry appears in the span, the while loop work.
I tried that but in the playback, if I point to a local page, sahi does not work
Thanks
To test local files,
Copy the local file into sahi/htdocs/demo directory.
Go to sahi/bin and start web.bat/web.sh
On the browser, navigate to http://localhost:10000/demo/yourlocalfile.html
If using IE7 use http://machinename:10000/demo/yourlocalfile.html
You could also try _spandiv(/.*Sorry.*/) just in case there are other characters/spaces in that span.