Mat*_*wek 6 java selenium docker
我有以下使用硒上传图像的方法。
public static void uploadSampleImage(StaticSeleniumDriver driver)
{
File file = new File(System.getProperty("user.dir") + "/resources/images/" + SAMPLE_DOCUMENT_FILE_NAME);
Utils.Log("file exists: " + file.exists());
String imagePath = file.getAbsolutePath();
WebElement input = driver.findElement(By.name("file"));
input.sendKeys(imagePath);
}
Run Code Online (Sandbox Code Playgroud)
这是提供文件路径(如 Guru99 教程中所述)以上传文件的标准方式。
org.openqa.selenium.InvalidArgumentException:无效参数:文件未找到:/usr/src/app/resources/images/image2.png(会话信息:chrome=72.0.3626.81)(驱动程序信息:chromedriver=2.46.628388(4a34a70826ea2ea2ea2705ac705) ),platform=Linux 4.9.125-linuxkit x86_64)(警告:服务器没有提供任何堆栈跟踪信息)
这很奇怪,因为我确定给定目录中存在文件(在我上面的方法中,我正在检查文件是否存在并且日志清楚地确认了这一点)
欢迎任何建议,谢谢
因为RemoteWebDriver你必须设置文件检测器driver.setFileDetector(new LocalFileDetector());。您的代码:
public static void uploadSampleImage(StaticSeleniumDriver driver)
{
driver.setFileDetector(new LocalFileDetector());
File file = new File(System.getProperty("user.dir") + "/resources/images/" + SAMPLE_DOCUMENT_FILE_NAME);
Utils.Log("file exists: " + file.exists());
String imagePath = file.getAbsolutePath();
WebElement input = driver.findElement(By.name("file"));
input.sendKeys(imagePath);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3465 次 |
| 最近记录: |