如何使用Windows文件资源管理器和Selenium WebDriver选择许多文件 [英] How to select many files using Windows file explorer with selenium webdriver

查看:279
本文介绍了如何使用Windows文件资源管理器和Selenium WebDriver选择许多文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动化一个UI测试,其中涉及选择要上传的文件,我能够使用此解决方案自动执行文件选择.

I am automating a UI test where selecting file to upload is involved, I was able to automate the file selection using this solution.

WebElement filepath=driver.findElement(By.id("fileUploadId"));
filepath.sendKeys("C:\\TextFile.txt");

我的问题是我需要选择许多要上传的文件,在发送的路径中我应该遵循一种特殊的格式吗?因为我尝试了用空格分隔的路径,但没有用.

My issue is that I need to select many files to upload, is there a special format I should follow in the path I am sending? because I tried space-separated paths and it didn't work.

推荐答案

上传多个文件,您可以构造字符字符串,并添加所有绝对路径\n分隔的文件,如下所示:

To upload multiple files you can construct the character string adding all the absolute path of the files seperated by \n as follows:

WebElement filepath = driver.findElement(By.id("fileUploadId"));
filepath.sendKeys("C:/TextFile1.txt \n C:/TextFile2.txt \n C:/TextFile3.txt");

这篇关于如何使用Windows文件资源管理器和Selenium WebDriver选择许多文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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