Closed iamxiaojianzheng closed 12 months ago
@iamxiaojianzheng, thank you for creating this issue. We will troubleshoot it as soon as we can.
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template
label.
If the issue is a question, add the I-question
label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted
label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-*
label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer
label.
Thank you!
This is only meant to be used for Grid, you are using a local Chrome. There is no need for this if you are using local downloads.
@titusfortner maybe we need something in the docs? Should we do something in the code?
Is it possible to add the function of downloadedFiles to ChromeDriver?
Local downloads already worked since a long time ago, you can set the browser preferences to define the location.
We need something in the docs, I'm still fighting the examples code in the CI.
@titusfortner maybe You can spot what am I doing wrong here by any chance? I might be missing something that You could add into the docs too. https://github.com/SeleniumHQ/selenium/issues/12695
I'm guessing you don't have grid started properly....
This works:
int port = PortProber.findFreePort();
Main.main(
new String[] {
"standalone",
"--port",
String.valueOf(port),
"--selenium-manager",
"true",
"--enable-managed-downloads",
"true"
});
URL gridUrl = new URL("http://localhost:" + port);
ChromeOptions options = new ChromeOptions();
options.setEnableDownloads(true);
driver = new RemoteWebDriver(gridUrl, options);
driver = new Augmenter().augment(driver);
driver.get("https://www.selenium.dev/selenium/web/downloads/download.html");
driver.findElement(By.id("file-1")).click();
driver.findElement(By.id("file-2")).click();
new WebDriverWait(driver, Duration.ofSeconds(5))
.until(d -> ((HasDownloads) d).getDownloadableFiles().contains("file_2.jpg"));
String fileName = ((HasDownloads) driver).getDownloadableFiles().get(0);
Path targetLocation = Files.createTempDirectory("download");
((HasDownloads) driver).downloadFile(fileName, targetLocation);
String fileContent = String.join("", Files.readAllLines(targetLocation.resolve(fileName)));
Assertions.assertEquals("Hello, World!", fileContent);
((HasDownloads) driver).deleteDownloadableFiles();
Assertions.assertTrue(((HasDownloads) driver).getDownloadableFiles().isEmpty());
@titusfortner - This was the reason https://github.com/SeleniumHQ/selenium/issues/12695#issuecomment-1790713161
I'm closing this one. I'll add conversation about this feature in the docs when I'm done with updating everything.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
What happened?
downloadsEnabled
, This variable is null.How can we reproduce the issue?
Relevant log output
Operating System
Windows 10
Selenium version
Java 4.15.0
What are the browser(s) and version(s) where you see this issue?
Chrome 119.0.6045.105
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 119.0.6045.105
Are you using Selenium Grid?
No response