1
    Greeting to Everyone, I am new to Automation, Learning and Exploring
    My Problem Statement is: 

I am trying to download PDF through a link, When I click on the link the PDF opens in a new window. By using Rest client I was able to download the pdf earlier (here end point was a single GET request), Now there is a backend changes happened where end point is changed to multiple post request.

The code I used so far:

        IWebDriver driver;
        var downloadloc = "C:\Users\Downloads" 
        public CookieContainer Cookies {get;set;}
        using(var client = new RestClient())
        {
          client.Endpoint = driver.findElement(By.xpath("Xpath of the PDF link")).GetAttribute("href");
          client.DownloadFile(pdflink, downloadLoc);
        }
        public bool DownloadFile(string url,string flnm)
        {
          EndPoint = url;
         using (var webClient = new WebClient())
         {
           webClient.Headers("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
           (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36");
           webClient.Headers.Add(HttpRequestHeader.Cookie, Cookies.GetCookieHeader(new Uri(EndPoint)));
           webClient.Proxy = System.Net.WebRequest.DefaultWebProxy;
           webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
           webClient.DownloadFile(EndPoint, flnm)
           
         }
        
        }

Does anyone have any possible solutions or insight into How to achieve the end goal? I'm still relatively new to programming and would appreciate any advice.

Please let me know, If any other information required.. Thanks in advance

  • Any insights on this. – Future Coder Oct 25 '22 at 15:50
  • This might be related to this old question. (I am not sure if browsers changed in this field): [Force to open "Save As..." popup open at text link click for PDF in HTML](https://stackoverflow.com/questions/3802510/force-to-open-save-as-popup-open-at-text-link-click-for-pdf-in-html) – Luuk Oct 25 '22 at 17:53
  • But you can also look at [(HTML) Download a PDF file instead of opening them in browser when clicked](https://stackoverflow.com/questions/6794255/html-download-a-pdf-file-instead-of-opening-them-in-browser-when-clicked) – Luuk Oct 25 '22 at 17:55

0 Answers0