java - 在 Selenium WebDriver 中捕获上传文件大小
问题描述
如果我想在使用 Selenium WebDriver 上传文件后捕获文件大小,是否有可能?顺便说一句,我正在使用 Java。目前我正在关注这个教程&这里是代码:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class upload {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","webdriver location");
String baseUrl = "http://demo.guru99.com/test/upload/";
WebDriver driver = new ChromeDriver();
driver.get(baseUrl);
WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
// enter the file path onto the file-selection input field
uploadElement.sendKeys("file location");
// check the "I accept the terms of service" check box
driver.findElement(By.id("terms")).click();
// click the "UploadFile" button
driver.findElement(By.name("send")).click();
}
}
我想在控制台中打印文件大小输出。我可以知道这个动作是否可行?谢谢。
解决方案
你的意思是这样的吗?它在上传之前打印上传文件的大小。
import java.io.File;
String fileName = "C:/users/something.txt";
File f = new File(fileName);
long fileSize = f.length();
System.out.format("The size of the file: %d bytes", fileSize);
推荐阅读
- php - 删除变量内的数组
- java - 如何从表单发送对象作为属性
- python - Python 查找并替换带有计算机主机名的通用 HOSTID
- python - 准备 JSON 以发布到 elasticsearch
- docker - 如何在 gitlab 的 Dockerfile 中包含 CI_JOB_TOKEN?
- sql - Oracle 程序编译 | 警告:执行完成但有警告
- grails - 为多个环境设置 SERVER_URL
- tensorflow - 无法导入 tensorflow - 奇怪的错误警报
- c++ - 无法从 GraphicScene 中选择自定义图形项
- visual-studio-2017 - Alt + Up 在向上移动行时滚动屏幕