Selenium webdriver 如何在selenium webdriver中单击图像
我一直在尝试点击网页上的图片。 此图像的Xpath为:Selenium webdriver 如何在selenium webdriver中单击图像,selenium-webdriver,Selenium Webdriver,我一直在尝试点击网页上的图片。 此图像的Xpath为: //*[@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
//*[@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
.findelelement(By
xpath
(“/*[@id='gridview-1018']/table/tbody
/tr[3]/td[7]/div/a/img”)。单击()WebDriverWait
wait=newWebDriverWait
(司机,60岁);
等待(ExpectedConditions.visibilityOfElementLocated
(By.cssSelector
(“x-grid-cell-inner.a.img”));
driver.findElement
(By.cssSelector
(“x-grid-cell-`internal.a.img”)。单击()driver
findelelement
(由.cssSelector`(“a[href='AbzorbDevelopment'])。单击()
感谢您的帮助您好,请使用具有以下语法的Actions类
Actions act = new Actions(driver);
act.moveToElement(xpath).click().build().perform();
嗨,请使用下面语法的Actions类
Actions act = new Actions(driver);
act.moveToElement(xpath).click().build().perform();
照拉杰说的去做。
使用Actions类
Actions act=操作(驱动程序);
act.moveToElement(xpath)。单击().build().perform();
但是,您是否可以尝试使用如下所示的CSS来代替这种绝对xpath:
div.x-grid-cell-internal>a[href=]http://demo.webshopondemand.com/Shop/AbzorbDevelopment/Store/“]>img[src='/admin/templates/images/house.png']
按照raj说的做,即。
使用Actions类
Actions act=操作(驱动程序);
act.moveToElement(xpath)。单击().build().perform();
但是,您是否可以尝试使用如下所示的CSS来代替这种绝对xpath:
div.x-grid-cell-internal>a[href=]http://demo.webshopondemand.com/Shop/AbzorbDevelopment/Store/“]>img[src='/admin/templates/images/house.png']
感谢Raj的回复。我尝试了以下代码:WebElement shop=driver.findElement((By.xpath(“/*[@id='gridview-1018']/table/tbody/tr[3]/td[7]/div/a/img”));Actions Actions=newactions(driver);Actions.moveToElement(shop).click().perform();收到的错误消息:找不到元素:{“方法”:“xpath”,“选择器”:“/*[@id='gridview-1018']/table/tbody/tr[3]/td[7]/div/a/img”}收到的错误消息:找不到元素:{“方法”:“xpath”,“选择器”:“/*[@id='gridview-1018']/表/t正文/tr[3]/td[7]/div/a/img“}表示您的xpath无效,请尝试提供有效的xpath,它肯定会工作xpath是。//*[@id='gridview-1018']/table/tbody/tr[3]/td[7]/div/a/imgform此处我无法验证您的xpath,因为我没有您页面的源代码(如果可能的话)请提供链接谢谢Raj的回复。我尝试了以下代码:WebElement shop=driver.findelelement((By.xpath(“/*[@id='gridview-1018']/table/tbody/tr[3]/td[7]/div/a/img”);Actions=new Actions(driver);actions.moveToElement(shop).click().perform();收到错误消息:找不到元素:{“方法”:“xpath”,“选择器”:“/*[@id='gridview-1018']]/table/tbody/tr[3]/td[7]/div/a/img”}收到错误消息:找不到元素:{“方法”:“xpath”,“选择器”:“/*[@id='gridview-1018']/table/tbody/tr[3]/td[7]/div/a/img“}表示您的xpath无效,请尝试提供有效的xpath它肯定会工作xpath是。//*[@id='gridview-1018']/table/tbody/tr[3]/td[7]/div/a/imgform此处我无法验证您的xpath,因为我没有您页面的源代码,如果可能,请提供链接给我