Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5689
  • Last Modified:

Automated WebBrowser C#

So my situation is I have a c# windows app with a WebBrowser in it.   The web browser is automated to direct to google adwords login page, put in the specified user/pass and click the login button.   After it has loaded the campaign page it scraps the page for the stuff I want and databases it, then it clicks the log out link and directs back to the login page.  This all works fine.  The code is set to wait for the page to load etc...  I have the program sleep for a couple minutes and then recurse on the code so that it runs again (Iam trying to keep a log of the click changes throughout the day).  The problem is that after the first time it logs in, each sequential time it logs in it is the same page with no updated statistics.  I have to shut the progam down and resart for it to get an update.  Is there possibly a way that I could clear my cache or delete my cookies or restart the session so that this doesn't happen?  Thanks
-Ty
0
TCash11
Asked:
TCash11
  • 3
2 Solutions
 
TCash11Author Commented:
I have tried to simply call the refresh fxn for the axWebBrowser every 2 minutes but it does not refresh properly; though If I manually do it (right click on the axWebBrowser and select refresh) it does it just fine.  What am I missing?
0
 
someman4onemanCommented:
Would you not consider using the webrequest and webresponse object to suck the page down
as this will give you more control.
If the user has to see the page you could set the
content of the browser to be what ever you recieved from the server.
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebresponseclasstopic.asp
0
 
TCash11Author Commented:
I am familiar with web requests and would do so, as I know they would probably offer me my solution, but I have the browser automated to login through the textboxs on the adwords login page so I need the browser.  Can I log in with the browser then do a web request?  Is their some way to tie the two together?  The user does not need to see the page, I just need to get an updated version of the page right after login every few minutes.  Thanks for your help it is much appreciated.
0
 
TCash11Author Commented:
I figured it out.  I added a class to my code to delete the internet cache.  I found the code for this class at http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q326/2/01.asp&NoWebContent=1
I did have to make a few changes to the code from that page though because it got stuck in the while loops if there was nothing in the cache.  In the first while loop (in Main()) add this to the very top:
if (ERROR_NO_MORE_ITEMS == Marshal.GetLastWin32Error()
      || ERROR_FILE_NOT_FOUND == Marshal.GetLastWin32Error())
{break;}

and in the second while loop (in Main) add this right below the first line (internetCacheEntry = ....) :
if (ERROR_NO_MORE_ITEMS == Marshal.GetLastWin32Error())
{break;}

After each time i loged in to adwords, got my stats, and logged back out, I ran the main fxn in the DeleteCache class (I had to name it something else rather than main since it was in the same namespace as the main of my program) and did a Thread.Sleep for a couple of minutes and started over.  Everything seems to work great now.  Thanks for your suggestions someman4oneman.  
-TCash
0
 
games0802Commented:
You can actually set your internet explorer to get a new page every time.  Go to Tools -> Internet Options -> Settings.  Look for "Check for newer version of stored pages:" and select "Every Visit".
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now