I'm currently creating some test cases with Selenium and I've come across a problem.
In my test case, the website I'm trying to walk through has a small form and a button to search. No problem filling the form and clicking the button. The problem comes once clicking the problem.
Once clicked the button, this function is called:
function muestraEspera(){
document.getElementById("divCargando").style.display = "";
}
Basically, this makes visible a DIV which contains an "loading" image so the visitor do just see the image and wont be able to actually see the website loading the content until finished (the content is loaded with ajax).
Once the content is loaded, this function is executed:
function escondeEspera(){
document.getElementById("divCargando").style.display = "none";
}
Which basically hides the "loading" DIV so the visitor can see the results.
Now, I can't use SLEEPS because loading can take more or less, and because I need the real execution time of the website. Is there any way (using java - junit4) to make selenium wait until the second function is executed before continuing with the next steps?
EDIT: I do use Selenium RC. To start the driver I use:
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "website-url");
selenium.start();
}
At the end, the solution that worked perfectly for me, given by Pavel Janicek is:
boolean doTheLoop = true;
int i = 0;
while (doTheLoop){
i= i+200;
Thread.sleep(1000);
if (i>30000){
doTheLoop = false;
}
if (!selenium.isVisible("id=divCargando")){
doTheLoop = false;
}
if (selenium.isVisible("id=divCargando")){
doTheLoop = true;
}
}
** EDIT 3**
So we have:
DefaultSelenium selenium = new DefaultSelenium("localhost",4444,"*iexplore", "websiteURL");
Still you can use the command isVisible
like this:
boolean doTheLoop = true;
int i = 0;
while (doTheLoop){
i = i+200;
Thread.sleep(200);
if (i>30000){
doTheLoop = false;
}
if (!selenium.isVisible("id=the ID Of element")){
doTheLoop = false;
}
}
Hope you will not end up in infinite loop.
I never worked with DefaultSelenium, so use please the isVisible()
function the same way as you are using the click()
for example.