英文:
Capture upload file size in Selenium WebDriver
问题
以下是您提供的代码的翻译部分:
package newpackage;
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位置");
String baseUrl = "http://demo.guru99.com/test/upload/";
WebDriver driver = new ChromeDriver();
driver.get(baseUrl);
WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
// 在文件选择输入框中输入文件路径
uploadElement.sendKeys("文件位置");
// 勾选“我接受服务条款”复选框
driver.findElement(By.id("terms")).click();
// 点击“上传文件”按钮
driver.findElement(By.name("send")).click();
}
}
请注意,代码部分已翻译,而问题部分不在翻译范围内。如果您有任何进一步的问题或需要帮助,请随时提问。
英文:
Is it possible if I want to capture the file size after I uploaded the files using Selenium WebDriver? Btw I'm using Java. Currently I'm following this one tutorial & here's the code:
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();
}
}
I want to print the file size output in console. May I know is this action is possible or not? Thanks.
答案1
得分: 1
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);
英文:
Do you mean something like this? It prints the size of the file uploaded prior to uploading.
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论