c# - C# Selenium 上传字节数组而不是文件
问题描述
我想看看是否可以使用 Selenium 将 FileStream(而不是 File)提交到 HTML 输入中。
场景是我需要自动上传文件,但这些文件不应该保存在机器中,因此使用字节数组。
由于 WebPortal 的复杂身份验证,我无法使用 http 请求。这就是使用 Chrome WebDriver 的原因。
private Tuple<bool, string> UploadFile(string fileName, byte[] fileContentClear, Customer destCustomer)
{
//chrome definition
//Selenium login into the portal and opening the Html File browser
//Select and submit file
string theFilePath = file.Replace('/', '\\'); //need to put backslash the filepath, else will fail
browser.FindElement(By.XPath(GetFileBtnXpath)).SendKeys(file); //insert the path in input box
//file will be a byteArray
IWebElement uploadAndSubmitButton = browser.FindElement(By.XPath(uploadSubmitBtnXpath));
uploadAndSubmitButton.Click(); //submit the file
}