java Selenium 按图像源定位元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26482517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium locating element by image source
提问by ayushi bakshi
I am trying to click on an element using selenium webdriver version 2.39, eclipse-kepler, IE11.
我正在尝试使用 selenium webdriver 版本 2.39、eclipse-kepler、IE11 单击一个元素。
I am getting the following error:
我收到以下错误:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //img[@src='images/style/default/menubar_menubutton.png'] (WARNING: The server did not provide any stacktrace information)
线程“main”org.openqa.selenium.NoSuchElementException 中的异常:无法找到带有 xpath == //img[@src='images/style/default/menubar_menubutton.png'] 的元素(警告:服务器没有提供任何堆栈跟踪信息)
Other things that give me the same error are:
其他给我同样错误的事情是:
(By.xpath("//div[contains(@src,'images/style/default/menubar_menubutton.png')]")); (By.xpath("//div[(@src,'images/style/default/menubar_menubutton.png')]")); (By,xpath("//img[contains(@src,'images/style/default/menubar_menubutton.png')]"));
(By.xpath("//div[contains(@src,'images/style/default/menubar_menubutton.png')]")); (By.xpath("//div[(@src,'images/style/default/menubar_menubutton.png')]")); (By,xpath("//img[contains(@src,'images/style/default/menubar_menubutton.png')]"));
回答by Sai Ye Yan Naing Aye
Try this;
试试这个;
WebElement temp = driver.findElement(By.xpath("//img[contains(@src,'images/style/default/menubar_menubutton.png')]"));
回答by Nitish Kumar
WebElement temp = driver.findElement(By.xpath("//*[contains(@src,'images/style/default/menubar_menubutton.png')]"));