Solved

Automated WebBrowser C#

Posted on 2004-04-22
5
5,677 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

734 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