概述
I'm using Selenium (within PHPUnit) to test my web application. I would like to test whether a certain image which is present on the page really exists. More precisely, whether the image url returns 404 or not. In order to test that, I need to get the image url. Given the image locator, How do I get the value of its src attribute (its url)?
解决方案
Assuming that you have an image in a WebElement (lets say img), in Java world you can retrieve the link below
Editing the answer to clarify.
By Java world I mean Selenium 2.0 Java bindings. In Selenium 2.0 (of course if you are using webdriver) has a class called WebElement representing elements on the page. getAttribute is a selenium Method in Java binding.
String url = "http://www.my.website.com";
WebDriver driver = new FirefoxDriver();
driver.get(url);
WebElement img = driver.findElement(By.id("foo"));
String src = img.getAttribute("src");
Perhaps there is something similar in PHPUnit
最后
以上就是内向老虎为你收集整理的java 获取src下的图片,Selenium:我如何获得图像的src?的全部内容,希望文章能够帮你解决java 获取src下的图片,Selenium:我如何获得图像的src?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复