enter image description here我一直试图点击网页上的图片。 此图片的X路是 - // * [@ 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;"/>`
在这里尝试了以下所有方法,但得到了相同的错误消息&#34;无法找到元素: -
driver
findElement(By
xpath
(&#34; .//* [@ ID =&#39; gridview的-1018&#39;] /表/ tbody
/ TR [3] / TD [7] / DIV /一个/ IMG&#34))点击();
WebElement temp = driver.findElement(By.xpath(&#34; // img [contains(@src,&#39; /admin/templates/images/house.png')]& #34)); temp.click();
WebDriverWait
wait = new WebDriverWait
(司机,60);
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector
(&#34; x栅格 - 细胞inner.a.img&#34)));
driver.findElement
(By.cssSelector
(&#34; x栅格 - 细胞`inner.a.img&#34))。单击()
4 driver
findElement
。(By.cssSelector`(&#34; [HREF =&#39; AbzorbDevelopment&#39;]&#34))。单击();
感谢您的帮助!
答案 0 :(得分:0)
您好请使用以下语法
的Actions类Actions act = new Actions(driver);
act.moveToElement(xpath).click().build().perform();
答案 1 :(得分:0)
像raj所说的那样做 使用Actions类
Actions act = Actions(driver);
act.moveToElement(xpath).click().build().perform();
但是不是这样的绝对xpath,你可以尝试使用CSS,如下所示:
div.x-grid-cell-inner>a[href='http://demo.webshopondemand.com/Shop/AbzorbDevelopment/Store/']>img[src='/admin/templates/images/house.png']
&#13;
您的最终实施将如下:
WebElement shop = driver.findElement((By.css("div.x-grid-cell-inner>a[href='http://demo.webshopondemand.com/Shop/AbzorbDevelopment/Store/']>img[src='/admin/templates/images/house.png']")));
动作动作=新动作(驱动程序); actions.moveToElement(商店)。单击()建立()执行();
请注意:上面的css路径是根据您在问题中提供的源代码创建的。