How to find the first instance of a pdf file using HTMLElement?

36 Views Asked by At
void DownloadFile(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    HtmlElementCollection links = webBrowser1.Document.Links;

    foreach (HtmlElement link in links)  // 
    {
        if (link.InnerText.Equals("*.pdf"))
        {
            link.InvokeMember("Click");
            break;
        }
    }
}

How do I find the first instance of a pdf file using HTML element. I was trying to do *.pdf but it does not work.

1

There are 1 best solutions below

0
On

Looks like you are using C#, you've tagged this as htmlelements which is a Java library, so you might have the wrong place.

However, if InnerText gets the link href (or if the link text contains the .pdf) then you probably want:

EndsWith(".pdf")

instead of

Equals("*.pdf").