Accessing links from JS in a WebBrowser object
Tag : chash , By : TRobison
Date : March 29 2020, 07:55 AM
like below fixes the issue Try SWAT or WatiNBoth are unit testing frameworks for automating web site front end testing, but can easily be used to traverse the DOM on a website as you want to do.
|
Accessing DOM from WebBrowser
Tag : chash , By : user185144
Date : March 29 2020, 07:55 AM
should help you out For the System.Windows.Controls.WebBrowser class you can use the Document property. Add mshtml reference to your project that should be available by right click on project and selecting Add Reference, then you should be able to cast it to mshtml.IHTMLDocument2 mshtml.IHTMLDocument2 htmlDoc = webBrowser.Document as mshtml.IHTMLDocument2;
// do something like find button and click
htmlDoc.all.item("testBtn").click();
|
Threads for WebBrowser.Print()
Date : March 29 2020, 07:55 AM
To fix this issue Main problem with your code is WebBrowser wrong using. WebBrowser supposed to be used for interactive web-browsing, during it user do some things in the internet. But in your case you are using WebBrowser just for the printing after downloading the html. This is wrong by two reasons: this.AxIWebBrowser2.ExecWB(NativeMethods.OLECMDID.OLECMDID_PRINT,
NativeMethods.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
ref obj,
IntPtr.Zero);
|
WebBrowser Threads don't seem to be closing
Tag : chash , By : vbanos
Date : March 29 2020, 07:55 AM
this will help WebBrowser is specifically designed to be used from inside a windows forms project. It is not designed to be used from outside a windows forms project. Among other things, it is specifically designed to use an application loop, which would exist in pretty much any desktop GUI application. You don't have this, and this is of course causing problems for you because the browser leverages this for its event based style of programming. public static string GetGeneratedHTML(string url)
{
string result = null;
ThreadStart pumpMessages = () =>
{
EventHandler idleHandler = null;
idleHandler = (s, e) =>
{
Application.Idle -= idleHandler;
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += (s2, e2) =>
{
result = wb.Document.Body.InnerHtml;
wb.Dispose();
Application.Exit();
};
wb.Navigate(url);
};
Application.Idle += idleHandler;
Application.Run();
};
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
pumpMessages();
else
{
Thread t = new Thread(pumpMessages);
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}
return result;
}
|
InvalidCastException when using webbrowser and threads in c#
Tag : chash , By : hammer_1968
Date : March 29 2020, 07:55 AM
it helps some times The WebBrowser doesn't like being accessed from other threads. Try passing it in to RunWorkerAsync() like this: private void button1_Click(object sender, EventArgs e)
{
HtmlDocument doc = web.Document;
m_oWorker.RunWorkerAsync(doc);
}
void m_oWorker_DoWork(object sender, DoWorkEventArgs e)
{
HtmlDocument doc = (HtmlDocument)e.Argument;
//NOTE : Never play with the UI thread here...
string line;
//time consuming operation
while ((line = sr.ReadLine()) != null)
{
int index = line.IndexOf(":");
Thread.Sleep(1000);
m_oWorker.ReportProgress(cnt);
//If cancel button was pressed while the execution is in progress
//Change the state from cancellation ---> cancel'ed
if (m_oWorker.CancellationPending)
{
e.Cancel = true;
m_oWorker.ReportProgress(0);
return;
}
cnt++;
}
//Report 100% completion on operation completed
m_oWorker.ReportProgress(100);
}
|