Selenium Driver | Bug | Instead of downloading pdf file opening in new window tab

Selenium Driver | Bug | Instead of downloading pdf file opening in new window tab



I'm new to selenium and I'm just search for PDF from Google and clicking on it so i can download it.



When I do manually. I'm able to download PDF file, while through Selenium driver when I click on the link its redirect to new browser tab and opening PDF while instead of showing download windows box.


FirefoxProfile profile= new FirefoxProfile();
profile.setPreference("browser.download.dir", "D:\Selenium");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/pdf;");


//Clicking on the pdf link. driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys("Download sample pdf");
driver.findElement(By.name("btnK")).click();
driver.findElement(By.xpath(".//*[@id='rso']/div/div/div[1]/div/div/h3/a")).click();
Thread.sleep(5000);





Possible duplicate of Selenium download file automatically c#
– Sers
Aug 30 at 6:44





try this 1. go to sample-videos.com/download-sample-pdf.php 2. use xpath //*[@class='download_pdf'] to click and download pdf file
– Amit Jain
Aug 30 at 7:30







Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Malaysia to Papua New Guinea by motorcycle?

.name

List of Bhojpuri films