8
<td colspan="2" align="center">
        <img src="web/L001/images/IMAGENAME.jpg" width="213" height="46" border="0" onclick="javascript: MessageDisplay()" ></td>

这是我要单击的元素。我尝试的代码:

WebElement temp = driver.findElement(By.xpath("web/L001/images/Phishing_12.jpg"));
temp.click();

我什至尝试了完整的地址,但任何想法都将不胜感激。

我用它来登录各种网站,但是这个特定的网站会弹出一个网页,然后我必须单击该元素才能继续。-谢谢

4

2 回答 2

16

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.

于 2013-08-23T16:19:47.300 回答
8

通常 CSS 选择器优于 xpath。这就是为什么我会推荐:

WebElement temp = driver.findElement(By.cssSelector("img[src='web/L001/images/IMAGENAME.jpg']"));
于 2013-08-23T16:23:30.320 回答