使用Robot类从Windows弹出窗口上传文件失败

时间:2019-02-12 13:30:55

标签: java selenium selenium-webdriver file-import

我正在使用下面的代码在我的应用程序中选择并导入一个csv文件。文件路径被粘贴了,我还可以看到导入的数据,但是我的测试用例仍然失败并且我无法弄清楚为什么。< / p>

$key = array_search('three', array_column($array, '?'));

1 个答案:

答案 0 :(得分:-1)

如果坚持使用机器人方法并不重要,建议您采用以下方式处理文件上传:

ObservableList

如果使用RemoteDriver,请不要忘记添加以下内容:

// Find file input element
WebElement input = driver.findElement(By.cssSelector("input[type='file']"));

// Make sure element is visible
((JavascriptExecutor) driver).executeScript("arguments[0].style.display = 'block';", input);

// Specify you local file path here
input.sendKeys("/path/to/file/on/machine/which/runs/tests");

注意:文件路径应该是绝对的。您可以通过以下方式实现:

// Configure your client to upload local files to remote Selenium instance
    driver.setFileDetector(new LocalFileDetector());
相关问题