我是靠谱客的博主 内向老虎,最近开发中收集的这篇文章主要介绍java 获取src下的图片,Selenium:我如何获得图像的src?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部