readikus readikus - 1 year ago 83
Java Question

Selenium Click Image Link based on Alt (including quote)

I have a tricky one!

I am trying to test an image button click in Selenium. This is the HTML code:

<a href="/"><img src="/img/buttons/showOnOrder.gif" alt="Show 'On Order'"/></a>

I completely agree that having the single quote in the alt text is not ideal/good, but for the purposes of this test, I can't currently change the code.

I have tried the following"//img[@alt=\"Show 'On Order'\"]");"xpath=//img[@alt='Show ''On Order''']");

But no joy. Please, please, please make my day and suggest the syntax I can use that works.

Answer Source

Try this :"//a[contains(@href,'onOrder')]/img");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download