Javascript 使用Fluentlenium在dropzone.js中上载文件
我希望编写一个测试,使用Fluentlenium和DropZone.js()上传一个文件。Dropzone.js以一种模式工作,然后您可以以正常方式拖放或上传 当您单击上载测试时,由于浏览器中不再显示您的文件,测试将崩溃 我在Selenium中找到了许多文章,这些文章都使用了以下内容:Javascript 使用Fluentlenium在dropzone.js中上载文件,javascript,selenium,dropzone.js,fluentlenium,Javascript,Selenium,Dropzone.js,Fluentlenium,我希望编写一个测试,使用Fluentlenium和DropZone.js()上传一个文件。Dropzone.js以一种模式工作,然后您可以以正常方式拖放或上传 当您单击上载测试时,由于浏览器中不再显示您的文件,测试将崩溃 我在Selenium中找到了许多文章,这些文章都使用了以下内容: WebElement fileInput = driver.findElement(By.xpath("//input[@type='file']")); fileInput.sendKeys("C:/path/
WebElement fileInput = driver.findElement(By.xpath("//input[@type='file']"));
fileInput.sendKeys("C:/path/to/file.jpg");
但是,我无法向任何东西发送密钥,因为在使用DropZone.js时,它们甚至不是输入type=“file”
我看到的唯一输入类型都是隐藏类型
<input type="hidden" name="key" value="temp/${filename}">
<input type="hidden" name="AWSAccessKeyId" value="secret">
<input type="hidden" name="acl" value="private">
<input type="hidden" name="success_action_redirect" value="">
<input type="hidden" name="policy" value="secret=">
<input type="hidden" name="signature" value="secret">
<input type="hidden" name="Content-Type" value="application">
我们也在使用Amazon Web Server上传文档,似乎一切都在按照以下脚本进行:
<script id="hiddenKeyPairs" type="text/javascript">
var hiddenKeyPairs = {
key: 'temp/${filename}',
AWSAccessKeyId: 'secret',
acl: 'private',
"success_action_redirect": '',
policy: 'secret',
signature: 'secret/secret',
"Content-Type": 'application'
};
var formAction = 'https://secret.com/';
</script>
var hiddenKeyPairs={
键:“temp/${filename}”,
AWSAccessKeyId:“秘密”,
acl:'私有',
“成功\u操作\u重定向”:“”,
政策:"秘密",,
签名:“秘密/秘密”,
“内容类型”:“应用程序”
};
var形成率https://secret.com/';
它位于我的页面上
我看不到任何有帮助的东西
我是否需要以某种方式将文件发送到上述脚本中的密钥散列
有什么想法吗?我对AWS部分不太清楚,但我对文件上传()和一些可能的解决方案也有类似的问题。我觉得它们不是很健壮,但基本上: 方法1:使用Java Robot模拟GUI操作-
// this opens the file browser window
driver.findElement(By.id("uploadDropzone")).click();
// put the file path in clipboard, paste (C-V) to the window, enter.
StringSelection ss = new StringSelection("some file path");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
Robot robot = new Robot();
Thread.sleep(2000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(5000); // need some wait for GUI action to work...
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER)
方法2:在代码中执行所有操作(hacky…)-是的,有一个文件输入元素,但仅在Dropzone.js中定义,可以使用$(“.dz隐藏输入”)
选择该元素。但您还必须使其可见(因为Selenium只能作用于可见元素),然后可以对其调用sendKeys
。然后,再次在Javascript中,从该元素中检索文件
对象,然后在Dropzone对象上传递到addFile(File)