Matt
Matt

Reputation: 95

selenium findElement by another thing than By.id

I'm quite new to this wonderfull tool that selenium is, and i'm trying to make some examples tests in my web app (html/JS). I managed to select some (most) elements withtheir id with the command driver.findElement(By.id("elementId")); but i'm unable to find some elements that do not have an id tag. I tried these following lines without result, as i have have an

This element HTML code is <img src="absolut/path/to/img.png" border="0" onclick="JSfunction(0)" alt="smthg" style="cursor: pointer;">

If somebody could help me, that would be very nice :) Thanks, and have a good day !

Upvotes: 2

Views: 5278

Answers (1)

Santoshsarma
Santoshsarma

Reputation: 5667

You can use either of below

By.cssSelector("img[alt='smthg'][src*='path/to/img']");

or

By.xpath("//img[@alt='smthg' and contains(@src,'path/to/img')]")

Upvotes: 4

Related Questions