Wednesday, May 8, 2013

GeckoFX trigger javascript _doPostBack() method

Here's how you fire a _doPostBack() in ASP.NET using GeckoFX.
Code:
           //fire js method  
           using (AutoJSContext context = new AutoJSContext(this.JSContext))  
           {  
             string result;  
             context.EvaluateScript(string.Format("javascript:__doPostBack('{0}','')",   
             paramControlName), out result);  
           } 

Cheers!

GeckoFX DocumentText similar to Webbrowser Control (C#)

In a traditional webbrowser control, you can get the page source like this:
Code:
string pageSource = webbrowser1.DocumentText; 
However, in GeckoFX webbrowser, there's no DocumentText property.
A workaround is to get the InnerHtml property of html tag using the code below:
Code:
string pageSource = string.empty;   
 if (!string.IsNullOrEmpty(this.Document.GetElementsByTagName("html")[0].InnerHtml))  
     pageSource = this.Document.GetElementsByTagName("html")[0].InnerHtml; 
Cheers!

Tuesday, May 7, 2013

GeckoFx getElementByID() click() method missing

In an application that i am creating using Gecko FX version 15, I noticed that getElementsByTagName() has an invoke member click() as shown below:
Code:
this.Document.GetElementsByTagName(geckoElement.TagName)[indexSearchElement].Click();
But missing in getElementByID(). After experimenting for a few hours, I came up with the solution below:
Code:
((GeckoHtmlElement)this.Document.GetElementById(elemId)).Click();  
The trick was to cast it as GeckoHtmlElement.
Greg

Sunday, May 5, 2013

WebClient slow in crawling (C#)

Here's a tip i got from stack overflow on webclient slow on web crawling.
1
2
3
ServicePointManager.DefaultConnectionLimit = int.MaxValue;  
 ServicePointManager.MaxServicePoints = int.MaxValue;  
 ServicePointManager.MaxServicePointIdleTime = 0; 
I simply changed the default connection limit and max service points
to a numeric value. Then, the crawling starts to speed up.

Greg