readikus readikus - 1 year ago 70
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="/targetPage.do?status=onOrder&"><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

selenium.click("//img[@alt=\"Show 'On Order'\"]");
selenium.click("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 :

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