Selenium WebDriver:上传多个文件 [英] Selenium WebDriver: Upload multiple files

查看:57
本文介绍了Selenium WebDriver:上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试需要在不同浏览器中上传测试文件(我使用WebDriver + Java).对于单个文件上传,一切正常.我只是发送路径

My test need to upload test files in different browsers (I use WebDriver + Java). For a single file upload, everything works fine. I just send the path

"C:\testdata\testfile.txt"
But, syntax changes for multiple upload and different browsers.

(
IE: 
""" + "C:\Selenium\TestData\Flexy - BigFile1.txt"+""" +"""+"C:\Selenium\TestData\Flexy - BigFile2.txt" + """

CHROME: 
"C:\Selenium\TestData\Flexy - BigFile1.txt"+"
"+"C:\Selenium\TestData\Flexy - BigFile2.txt".

Firefox:我找不到正确的语法.

Firefox: I'm not able to find a correct syntax.

有什么想法吗?

是否有适用于所有浏览器的通用语法?

Is there a common syntax for all browsers?

推荐答案

据我所知,selenium 仍然不支持多文件上传(见谷歌代码问题).

As far as I know, selenium still does not support multiple file upload (see issue on google code).

至少有一种解决方法:显然创建一个包含任意数量输入字段的表单(参见 另一个stackoverflow 问题).不是最好的解决方案,因为它(可能)需要更改您的代码才能使 selenium 工作.

There is at least one workaround: apparently create a form that contains as many input fields as you need (see another stackoverflow question). Not the best solution, as it (probably) requires altering your code for selenium to work.

但是,正如您所发现的(感谢您!),似乎可以在 chrome 和(虽然我没有测试)IE 中触发多个文件上传.

However, as you have found out (thanks for this!), it does seem possible to trigger multiple file uploads in chrome and (although I did not test it) IE as well.

我刚刚确认 chrome " " 技巧在本地和 Browserstack 上都有效(我使用了他们提供的默认图像),考虑到事物的状态,这对我来说已经足够了.

I just confirmed that the chrome " " trick works both locally and on Browserstack (I used the default images they provide), which, considering the state of things, is good enough for me.

我希望这会有所帮助.

这篇关于Selenium WebDriver:上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆