繁体   English   中英

在Java中使用Selenium WebDriver无法上传文件

[英]failed to upload a file using selenium webdriver in Java

我正在尝试使用Selenium Webd River上传文件,但无法使该Spinet代码正常工作

driver.findElement(By.id("uploadForm:j_id135")).sendKeys("path_to_file");
driver.findElement(By.name("uploadForm:j_id139")).click();

我也尝试过以下建议: 使用Selenium WebDriver和Java进行文件上传对我来说太糟糕了

有什么想法吗?

当您手动单击以上传文件时(在手动工作时),将提供实际输入框(提供路径的位置)的“ id”。 在自动化方案中,我们需要使用以下命令来提供该输入框的正确ID:

driver.findElement(By.id(“ upload”))。sendKeys(“ / path / to / the / file”);

下一步当然是单击“上传”按钮。

如果您使用的是WebDriverBackedSelenium,则可以使用:

selenium.type(“ locator”,“ / path / to / the / file”);

selenium.click(“ upload_button”);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM