One possible method to use Selenium and Java to click the download icon of a PDF that has been opened in a new tab is:
String currentHandle = driver.getWindowHandle();
for (String handle : driver.getWindowHandles()) {
if (!handle.equals(currentHandle)) {
driver.switchTo().window(handle);
break;
}
}
WebElement downloadIcon = driver.findElement(By.cssSelector("a[title='Download PDF']"));
downloadIcon.click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.tagName("body")));
Note that the exact details of the code will depend on the specific website and PDF viewer being used, and may require additional steps such as handling pop-up dialogs or specifying a download folder.
Asked: 2023-03-07 11:00:00 +0000
Seen: 12 times
Last updated: Apr 09 '22