[英]how do I get the size of the file before upload using Selenium
I've been trying for days to do this.. 我已经尝试了好几天了。
I want to simply get the size of the file before it is uploaded. 我只想在上传之前获取文件的大小。
something like this: 像这样的东西:
IWebElement element = driver.FindElement(By.Id("FileUpload"));
string fileSizeInKB = element.GetAttribute("files[0].size");
or this: 或这个:
IWebElement element = driver.FindElement(By.Id("FileUpload"));
string fileSizeInKB = element.GetAttribute("files")[0].size;
neither of these ways works so I'm asking how I could archive something similar? 这两种方式都不起作用,所以我问如何归档类似的东西?
You can use the System.IO.File namespace 您可以使用System.IO.File命名空间
byte[] buffer = System.IO.File.ReadAllBytes(@"yourfilename");
int size = buffer.Length;
Update 更新
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
string title = (string)js.ExecuteScript("Your JavaScript Here");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.