在本地运行时,以下命令可以正确执行:
String fileLocation = "/Users/local/file.xlsx";
chro.findElement(By.xpath("//input[@title='input']")).sendKeys(fileLocation);
但是在远程运行(在硒网格上)时失败,但发生以下异常:org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : /Users/local/file.xlsx
有人知道原因吗?
答案 0 :(得分:0)
根据您收到的错误,似乎在执行脚本的服务器上不存在路径/Users/local/file.xlsx
。
要解决此问题,您可以在自动化项目中创建一个名为folder
的{{1}},在该文件夹中可以插入测试数据excel表exceldata
,然后可以设置使用file.xlsx
的路径(它提供当前系统上的项目目录路径),然后可以使用以下命令设置xlsx路径:
System.getProperty("user.dir")
现在,以上String fileLocation = System.getProperty("user.dir") + "/exceldata/file.xlsx";
并不依赖于您正在运行脚本的计算机,并且可以在任何地方独立使用。
答案 1 :(得分:0)
找到了答案-stackoverflow.com/a/16244627/9336888
TLDR:使用FileDetector通过网络发送文件。
driver = new RemoteWebDriver(new URL(hubUrl), options);
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());