enter image description here I 've been trying to click on an image on web page. Xpath for this image is - //*[@id=' gridview-1018'] / table / tbody / tr [3] / td [7] / div / a / img
HTML代码是 -
<td class=" x-grid-cell x-grid-cell-gridcolumn-1016 ">`<div class="x-grid-cell-inner " style="text-align: center; ;">`<a href="http://demo.webshopondemand.com/Shop/AbzorbDevelopment/Store/" target="_blank">`<img src="/admin/templates/images/house.png" style="background-color: transparent;"/>`
尝试了以下所有方法,但得到了相同的错误信息“无法找到元素: -
-
driver
.findElement(By
.xpath
(“.// * [/ id = 'gridview-1018'] / table /tbody
/ tr [3] / td [7] / div / a / img”)) . click(); -
WebElement temp = driver.findElement(By.xpath(“// img [contains(@src,'/ admin / templates / images / house.png')]”)); temp.click();
-
WebDriverWait
wait = newWebDriverWait
(driver,60); wait.until(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector
("x-grid-cell-inner.a.img")));driver.findElement
(By.cssSelector
("x-grid-cell-`inner.a.img")) . click()
driver
.findElement
(By.cssSelector`("a[href='AbzorbDevelopment']")) . click();
谢谢您的帮助!
2 回答
嗨,请使用以下语法的Actions类
像raj所说的那样使用Actions类
Actions act = Actions(driver); act.moveToElement(xpath).click().build().perform();
但是,如果没有这样的绝对xpath,你可以尝试使用CSS,如下所示:
你的最终实现将是:
动作动作=新动作(驱动程序); . actions.moveToElement(商店) . 单击() Build ()执行();
请注意:上面的css路径是根据您在问题中提供的源代码创建的 .