selenium - 如何使用 Selenium(任何版本)下载图像?

标签 selenium webdriver

我想知道,如何使用 selenium/webdriver 下载页面的图像。假设需要用户 session 来下载图像,因此使用纯 URL 没有帮助。任何示例代码都受到高度赞赏。

最佳答案

我更喜欢做这样的事情:

1. Get the SRC attribute of the image.
2. Use ImageIO.read to read the image onto a BufferedImage
3. Save the BufferedImage using ImageIO.write function

例如

String src = imgElement.getAttribute('src');
BufferedImage bufferedImage = ImageIO.read(new URL(src));
File outputfile = new File("saved.png");
ImageIO.write(bufferedImage, "png", outputfile);

关于selenium - 如何使用 Selenium(任何版本)下载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6813704/

相关文章:

python - 使用 python 在已打开的对话框中选择一个文件

video - 录制视频播放的 Selenium 测试(ffmpeg)

selenium - 如何等到 Selenium WebDriver 中的页面卡住?

python - 如何使用Python和Selenium库与深度嵌套的 'input' html对象交互

java - 无法使用 WebDriver 从下拉列表的选项中获取文本值

java - Selenium 中的动态下拉菜单

java - 在标题数据和第一列数据匹配的位置选择一个文本框

google-chrome - WebDriver异常: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser

java - 如何使用带有 Java 的 Selenium WebDriver 处理日历弹出窗口?

python - WebElement.find_element_by_class_name 是否仅在直接子级中搜索 [WebDriver/Python]