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

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

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);

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:

确定