HTML:
<img src="dash_img/dash-img_07.png">
HTML图片:
这里没有获取xpath的属性,我通过链接文本尝试过,但这太失败了。
答案 0 :(得分:0)
要找到该元素,可以使用以下任一解决方案:
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 (基于文本查看时间表):
//span[contains(., 'View Timesheet')]//preceding::a[1]/img
答案 1 :(得分:0)
您可以使用此xpath找到它
WebElement temp = driver.findElement(By.xpath("//img[contains(@src,'<img src="dash_img/dash-img_07.png">')]"));
答案 2 :(得分:0)
或
"//div[@class='list']//a/img"
答案 3 :(得分:0)
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]