I need to get a download link from a site. to get it i need to wait 10 seconds until it will be available to click. is is possible to get the download link with WebBrowser()?
this is the source of button.
<input type="submit" id="btn_download" class="btn btn-primary txt-bold" value="Download File">
this is what i tried:
WebBrowser wb = new WebBrowser();
wb.ScriptErrorsSuppressed = true;
wb.AllowNavigation = true;
wb.Navigate(url);
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
Thread.Sleep(10000);
HtmlElement element = wb.Document.GetElementById("btn_download");
element.InvokeMember("submit");
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
string x = wb.Url.ToString();
what is wrong here?
Edited - tried this but still not working - btw i think i little messed up the code I'm noob :)
public void WebBrowser()
{
WebBrowser wb = new WebBrowser();
wb.ScriptErrorsSuppressed = true;
wb.AllowNavigation = true;
wb.Navigate(URL);
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
while (wb.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
wb.Dispose();
}
public void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser wb = (WebBrowser)sender;
string x = wb.Url.ToString();
if (!x.Contains("server")) // download link must conatin server
{
System.Timers.Timer t = new System.Timers.Timer();
t.Interval = 10000;
t.AutoReset = true;
t.Elapsed += new ElapsedEventHandler(TimerElapsed);
t.Start();
HtmlElement element = wb.Document.GetElementById("btn_download");
element.InvokeMember("Click");
while (wb.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
}
else
MessageBox.Show(x);
}
public void TimerElapsed(object sender, ElapsedEventArgs e)
{
Application.DoEvents();
}