Solved

Automated WebBrowser C#

Posted on 2004-04-22
5
5,672 Views
Last Modified: 2013-11-13
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
Comment
Question by:TCash11
  • 3
5 Comments
 

Author Comment

by:TCash11
ID: 10893962
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
 
LVL 1

Assisted Solution

by:someman4oneman
someman4oneman earned 250 total points
ID: 10895102
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
 

Author Comment

by:TCash11
ID: 10896207
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
 

Author Comment

by:TCash11
ID: 10903994
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
 
LVL 1

Accepted Solution

by:
games0802 earned 250 total points
ID: 10906392
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question