Reputation: 13
HTML:
<img src="dash_img/dash-img_07.png">
HTML Image:
Here there is no attribute to get the xpath, I tried by link text but that too failed.
Upvotes: 0
Views: 127
Reputation: 25714
I think the most straightforward way to find it would be to use a CSS selector
img[src='dash_img/dash-ig_07.png']
or XPath
//img[@src='dash_img/dash-ig_07.png']
CSS selectors are faster, better supported, and a simpler syntax to learn but there are times when you have to use XPath, e.g. when you want to find an element by contained text.
But... I would suggest that you find it based on the image label, "View Timesheet",
//span[.='View Timesheet ']/preceding::img[1]
Upvotes: 1
Reputation: 193338
To locate the element you can use either of the following solutions:
CssSelector:
div.Timesheet li.time-bg > a > img[src='dash_img/dash-img_07.png']
XPath:
//div[@class='Timesheet']//li[@class='time-bg']/a/img[@src='dash_img/dash-img_07.png']
XPath (based on the text View Timesheet):
//span[contains(., 'View Timesheet')]//preceding::a[1]/img
Upvotes: 1
Reputation: 1905
You can use this xpath should find it
WebElement temp = driver.findElement(By.xpath("//img[contains(@src,'<img src="dash_img/dash-img_07.png">')]"));
Upvotes: 0