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

查看:101
本文介绍了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"+"\n"+"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?

推荐答案

据我所知,硒 still 不支持多个文件上传(请参阅

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

至少有一种解决方法:显然创建一个包含所需输入字段的表单(请参阅

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"\ n"技巧在本地和Browserstack上都有效(我使用了它们提供的默认图像),考虑到事物的状态,这对我来说已经足够了.

I just confirmed that the chrome "\n" 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.

我希望这会有所帮助.

I hope this helps.

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

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