java - Selenium:无法从 Intellij 中 Java 项目的本地目录上传文件
问题描述
System.out.println("LC13.2 started");
//Locate the element name 'Dokument Auswahlen'
WebElement DokUpload = driver.findElement(By.xpath(property.getProperty("DokumentSelection_ButtonXpath")));
String FilePath = ".\\resources\\SyncPilot_Showformular_Testing.pdf";
DokUpload.sendKeys(FilePath);
解决方案
使用 sendKeys 上传文件需要绝对路径,我们发送的是位置而不是文件。所以当它到达前端当前目录时不会是你的硒当前目录..所以那个路径中不会有任何文件
使用路径生成器创建绝对路径
System.getProperty("user.home") + /file/relativepath/file.pdf
推荐阅读
- python - 运行 Flask 单线程
- automapper - Automapper 8.1.1 在更新到 Abp 4.8.1 后使用反射不起作用
- python-2.7 - 为什么数据会跨请求保留?
- node.js - 2019年Node.JS进程之间如何通信
- python - 绘制多条线时 X 轴偏移
- scala - rdd.count,count via spark sql的结果是一样的,但是和hive sql的count结果是不一样的
- mysql - 如果目标在一张表中而活动在另一张表中,如何显示实现不同目标的进度
- python - 删除数字及其后面的任何特殊字符或字母(来自邮政地址)
- android - Android InAppBillingV3 购买并检查商品是否已购买
- c++ - 搜索和限制特定文件类型 VS2017