3
votes

How can I write a keyword for my test case with Selenium2Library to click on a button with no element id?

Below is the html code. I am new to selenium!

<a href="redirect.cfm?app=profile">
<div id="profile" class="icon">
<img style="display:block; margin:0 auto;" src="assets/images/profile.png">
<h3>Profile</h3>
</div>
</a>

I've tried

driver.findElement(By.Xpath("//img[@src='assets/images/profile.png']")).click();

But got the error:

LoginTest
| FAIL | ValueError: Element locator with prefix 'driver.findElement(By.Xpath("//img[@ src' is not supported

1

1 Answers

4
votes

If you're actually using Robot Framework then to make use of the functionality you simply need to ensure the library is imported then use the keyword you need.

To be explicit, in the settings section:

Library     Selenium2Library 

and in the test case or keyword:

Selenium2library.Click Element    xpath=//img[contains(@src, 'profile.png')]

Assuming that your xpath is correct. Given the poor locator, generally what you want to do is have ids added to things you need.