How to recognize a image button using its alt text

4,802 views
Skip to first unread message

sumit sahu

unread,
Mar 14, 2011, 5:10:34 AM3/14/11
to webdriver
What is the command to find Element by its alt text?
eg.
<a href="http://cart.half.qa.ebay.com/ws/eBayISAPI.dll?
ShoppingCart&amp;action=additem&amp;itemid=90000999992&amp;pr=8771532"><img
src="http://pics.qa.ebaystatic.com/aw/pics/half/buttons/
btnBuy_46x26.gif" border="0" alt="Buy!"></a>

Here, alt="Buy!". How to recognize it?

Danny Guerrier

unread,
Mar 14, 2011, 6:47:31 PM3/14/11
to webd...@googlegroups.com
Findby xpath //a[@alt='Buy!']

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>

Bill Ross

unread,
Mar 14, 2011, 6:47:20 PM3/14/11
to webd...@googlegroups.com
> What is the command to find Element by its alt text?
> eg.
> <a href="http://cart.half.qa.ebay.com/ws/eBayISAPI.dll?
> ShoppingCart&amp;action=additem&amp;itemid=90000999992&amp;pr=8771532"><img
> src="http://pics.qa.ebaystatic.com/aw/pics/half/buttons/
> btnBuy_46x26.gif" border="0" alt="Buy!"></a>
>
> Here, alt="Buy!". How to recognize it?

WebElement we = driver.findElement(By.xpath("//img[@alt='Buy!']");

Eran M.

unread,
Mar 15, 2011, 3:04:11 PM3/15/11
to webd...@googlegroups.com, sumit sahu
Other than the tips suggested in this thread you could, of course, use eBay's API - it'll be faster, to start with.

Eran

JohnMc

unread,
Mar 15, 2011, 5:08:24 PM3/15/11
to webdriver
I find css to be faster

WebElement we =
driver.findElement(By.cssSelector("img[@alt='Buy!']");

On Mar 16, 6:04 am, "Eran M." <eran....@gmail.com> wrote:
> Other than the tips suggested in this thread you could, of course, use
> eBay's API - it'll be faster, to start with.
>
> Eran
>
Reply all
Reply to author
Forward
0 new messages