捕捉上传文件大小于Selenium WebDriver中

huangapple go评论95阅读模式
英文:

Capture upload file size in Selenium WebDriver

问题

以下是您提供的代码的翻译部分:

  1. package newpackage;
  2. import org.openqa.selenium.*;
  3. import org.openqa.selenium.chrome.ChromeDriver;
  4. public class upload {
  5. public static void main(String[] args) {
  6. System.setProperty("webdriver.chrome.driver","webdriver位置");
  7. String baseUrl = "http://demo.guru99.com/test/upload/";
  8. WebDriver driver = new ChromeDriver();
  9. driver.get(baseUrl);
  10. WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
  11. // 在文件选择输入框中输入文件路径
  12. uploadElement.sendKeys("文件位置");
  13. // 勾选“我接受服务条款”复选框
  14. driver.findElement(By.id("terms")).click();
  15. // 点击“上传文件”按钮
  16. driver.findElement(By.name("send")).click();
  17. }
  18. }

请注意,代码部分已翻译,而问题部分不在翻译范围内。如果您有任何进一步的问题或需要帮助,请随时提问。

英文:

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:

  1. import org.openqa.selenium.*;
  2. import org.openqa.selenium.chrome.ChromeDriver;
  3. public class upload {
  4. public static void main(String[] args) {
  5. System.setProperty("webdriver.chrome.driver","webdriver location");
  6. String baseUrl = "http://demo.guru99.com/test/upload/";
  7. WebDriver driver = new ChromeDriver();
  8. driver.get(baseUrl);
  9. WebElement uploadElement = driver.findElement(By.id("uploadfile_0"));
  10. // enter the file path onto the file-selection input field
  11. uploadElement.sendKeys("file location");
  12. // check the "I accept the terms of service" check box
  13. driver.findElement(By.id("terms")).click();
  14. // click the "UploadFile" button
  15. driver.findElement(By.name("send")).click();
  16. }
  17. }

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.

  1. import java.io.File;
  2. String fileName = "C:/users/something.txt";
  3. File f = new File(fileName);
  4. long fileSize = f.length();
  5. System.out.format("The size of the file: %d bytes", fileSize);

huangapple
  • 本文由 发表于 2020年9月28日 13:43:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64096528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定