I spent a little bit of time yesterday trying to figure out how to use Selenium to check for the presence or absense of a specific image used as the background of an HTML table. It wasn’t that hard to do in the end, but I got a little tripped up trying to check for the wrong thing. Pretty cool once I got it done, so I figured I’d share here.
What I tried to do:
At first I tried to grab the HTML text inside the TD and verify the presence of the filename of the image as text.
What I should have done all along:
What ended up working was that I knew the table row and cell in which I was expecting the image, and I had to do a “verifyElementPresent” instead. (Thanks to Dean for helping me figure that out)
The only thing I don’t like about that approach (vs. checking for text) is that I can’t do a wildcard search for the text. I have to exactly check for the full path to the file. So, if we decide to re-organize the directory structure and move some images to a “saltwater” and some to a “freshwater” subdirectory, the selenium test is then fragile and breaks. But chances are the images are going to remain pretty static, so I am happy enough with this approach.