How to click an image with Selenium with only an SRC

This xpath should find it

WebElement temp = driver.findElement(By.xpath("//img[@src='web/L001/images/IMAGENAME.jpg']"));

or use contains like so

WebElement temp = driver.findElement(By.xpath("//img[contains(@src,'web/L001/images/IMAGENAME.jpg')]"));

But i think the problem would be is that you are not waiting for the element.


Generally CSS selectors are favored over xpaths. That's why I would recommend:

WebElement temp = driver.findElement(By.cssSelector("img[src='web/L001/images/IMAGENAME.jpg']"));