I was playing around with Selenium RC a little while ago and ran into a little problem that I thought I would share with everyone. I was writing a test that bounced around WorkXpress to give me some performance benchmarks. My test added a new item that had a list layout of related items on it. I wanted to be able to follow a link to add items to that list. Seems easy enough right?
The difficult part came when I needed to wait for the layout to be reloaded
after adding the Items to it. I knew that when the layout reloaded there
was going to be a specific element on the page that was not there before. I
Testing_Selenium::waitForCondition() but that always returned right
away and let the processing continue. After a little help from the documentation
and Stack Overflow, I decided to give
When I tried calling
waitForCondition(), I received a
string back informing me that the element did not exist. This confirmed my
waitForConidtion() was coming back too early. I could have
added a call to
sleep() before continuing, but that would have defeated the
purpose of my test. Without a better solution, I resorted to a while loop
that exited when the element finally existed. The code I used is included below:
Be very careful when attempting to do anything like this. If the element never appears on screen, you will find yourself with an infinite loop. Let me know what you think, or if you have a better solution.