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