如何仅使用SRC单击带有硒的图像


<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();

我什至尝试使用完整的地址,但任何 ides 将不胜感激。

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

这个 xpath 应该能找到它

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

或使用包含这样的内容

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

但我认为问题是你没有wait元素。

通常,CSS 选择器比 xpath 更受青睐。这就是为什么我会推荐:

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

最新更新