How to assert the src of an image in Selenium?

6,751 views
Skip to first unread message

srinuchik...@gmail.com

unread,
Jan 22, 2009, 5:47:21 AM1/22/09
to webdriver
Hi ,

I am trying to automate a few test cases using selenium. As a part of
this, I need to assert a check box being checked/unchecked. The check
box in my application is an image and the image changes according to
the status.

If it is checked the image src would be "/.../.. /image_true.png",
if unchecked, the src would be "/.../.. /image_false.png"

The image has 'id' as another attribute using which it can be
identified. I tried to use the following code to do the assertion.

Selenium.isElementPresent("//img[@id='id12233445', @src='/x/images/
status_false.png']")

But it returns false, when I try to find the image with both the
attributes(id and src).

Please help me in this regard.

Thanks,
Srinivas Chikalavalasa

Simon Stewart

unread,
Jan 22, 2009, 9:39:31 AM1/22/09
to webd...@googlegroups.com
Hi Srinivas,

You've actually managed to land on the WebDriver support group.
WebDriver will be part of Selenium 2, but for now the two projects are
just good friends. I'll do my best to answer your question, though
I'll answer it for WebDriver first, and then with the equivalent
Selenium commands :)

WebElement image = driver.findElement(By.id("id12233445"));
String src = image.getAttribute("src");
return src.endsWith("image_true.png");

And now with Selenium.

String src = Selenium.getAttribute("id=id12233445@src");
return src.endsWith("image_true.png");

Hope that's useful to you!

Regards,

Simon

srinivas ch

unread,
Jan 22, 2009, 11:43:07 AM1/22/09
to webd...@googlegroups.com
Many Thanks for the solution Simon :) This helped me solve the problem
 
Srinivas C

Reply all
Reply to author
Forward
0 new messages