我必须将任何图像上传到网页以创建在线商店以继续测试。我必须点击按钮上传,然后我必须提供文件的目录,但我不能提供本地目录,因为测试在 Saucelabs 上的 VM 上运行。如何解决这个问题呢?
问问题
1090 次
1 回答
0
使用LocalFileDetector
类。您的代码将如下所示:
// WARNING!! Untested code written from memory, without benefit of an IDE.
// May not work exactly correctly or even compile without modification.
// Assume driver is a properly instantiated IWebDriver object, which is
// to be used with a remote service (including SauceLabs or similar).
IAllowsFileDetection fileDetectionDriver = driver as IAllowsFileDetection;
fileDetectionDriver.FileDetector = new LocalFileDetector();
IWebElement fileElement = driver.FindElement(By.Id("idOfFileInputElement"));
fileElement.SendKeys(@"C:\path\to\local.file");
通过设置文件检测器,该SendKeys
方法首先将文件从本地系统上传到实际运行代码的远程机器上。然后SendKeys
将在<input>
元素中设置文件,使用远程机器上的本地文件路径。
于 2014-07-28T01:06:38.900 回答