Webbrowser Frames
Webbrowser Frames
Webbrowser Frames
Webbrowser Frames
Webbrowser Frames
Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames
Webbrowser Frames Webbrowser Frames
Webbrowser Frames
Go Back  Xtreme Visual Basic Talk > > > Webbrowser Frames


Reply
 
Thread Tools Display Modes
  #1  
Old 10-17-2005, 04:37 PM
homerjay7 homerjay7 is offline
Newcomer
 
Join Date: Oct 2005
Posts: 19
Default Webbrowser Frames


I am using a webbrowser to automatically get excel spreadsheets off of a customer's website. I am able to log in, and now I need to click on a link that's in a frame of the page that the login takes me to. I tried to use

.SendKeys.Send("^({TAB})")

to ALT-TAB back to get to the link and then I was going to sendkeys ENTER to go to the link. However, I cannot tab back to the frame I need to be on. Any help would be appreciated.
Reply With Quote
  #2  
Old 10-18-2005, 04:10 PM
herilane's Avatar
herilaneWebbrowser Frames herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

I doubt that you actually need to click the link to download a file.
Example:
Code:
'get the html of the link you want Dim s As String With Me.WebBrowser1 .Navigate ("www.google.com") Do While .ReadyState <> WebBrowserReadyState.Complete Application.DoEvents() Loop Dim t As HtmlElement = .Document.Links(0) s = t.OuterHtml End With '... 'extract URL from HTML snippet, by stripping of unnecessary parts '... 'now download the file Dim web As New System.Net.WebClient web.DownloadFile(s, fileName)
Reply With Quote
  #3  
Old 10-19-2005, 10:27 AM
homerjay7 homerjay7 is offline
Newcomer
 
Join Date: Oct 2005
Posts: 19
Default

Sorry, I wasn't clear about the navigation. After logging in, I go to 2 pages before getting to the page with the Excel spreadsheet that I need to download.

I figured out how to click on the link in another frame (my original question), so I'm at the final page. On it, there are 2 text boxes with dates (I just leave these at their defaults) and a Submit button. When the Submit button is clicked, a new window opens with the Excel spreadsheet in it, so I don't know the filename of the spreadsheet.

I hope that makes semi-sense. Any idea how I can automatically get the spreadsheet and save it to my network drive?

Thanks for the help.
Reply With Quote
  #4  
Old 10-19-2005, 03:24 PM
herilane's Avatar
herilaneWebbrowser Frames herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

Example of filling in a textbox and submitting a form:
Code:
With Me.WebBrowser1 .Navigate ("www.google.com") Do While .ReadyState <> WebBrowserReadyState.Complete Application.DoEvents() Loop Dim t As HtmlElement t = .Document.All("Q") t.SetAttribute("value", "Who is John Galt") t = .Document.Forms(0) t.InvokeMember("submit") End With
I don't know how you would actually get the resulting Excel spreadsheet, though... It would be a lot easier if I could see the web page in question.
Reply With Quote
  #5  
Old 10-19-2005, 03:59 PM
homerjay7 homerjay7 is offline
Newcomer
 
Join Date: Oct 2005
Posts: 19
Default

Sorry, it's a customer's site that we have to log on to in order to view the page. The page consists of a From Date textbox, a To Date textbox, and a Submit button. I don't need to change the dates at all, just Submit. Once I do that, a new IE window opens and has the Excel spreadsheet in it, but I don't know what to do from there.

Here's the basics of the page:

<form name="Tower" method="post" action="SCMS;jsessionid=DWy2C7MDy1ZQpTNjLDMvkJvjJYhp9JKLnwjttNY5PLspfp tnfkBP!-1024602316!-1427608396" onSubmit="return checkandsubmit();">

<input type="hidden" name="action">
<div align="center">
<p class="pageheading">Tower Report</p>

<table width="70%" border="0" class="border">
<tr>
<td class="textlabel" width="35%">Plant</td>
<td colspan="2" width="65%" class="text">
<input type="hidden" name="plantCode" value="US2D" READONLY>
US2D
</td>
</tr>

<tr>
<td class="textlabel" width="35%">From Date</td>
<td width="30%">
<input class="textfield" type=text name="fromDate" size=10 READONLY>
<a href="javascript:cal1.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click here to select the date."></a>
</td>
<td width="35%" class="textlabel">
(40 Days Ago: <span class="text"><script type="text/javascript">document.write(daysAgo40String)</script></span>)
</td>
</tr>
<tr>
<td class="textlabel" width="35%">To Date</td>
<td width="65%" colspan="2">
<input class="textfield" type=text name="toDate" size=10 READONLY>
<a href="javascript:cal2.popup();"><img src="images/cal.gif" width="16" height="16" border="0" alt="Click here to select the date."></a>
</td>
</tr>

<tr>
<td colspan="3">
<div align="center">
<input class="buttonstyle2" type="submit" name="Submit" value="Submit">
</div>
</td>
</tr>
</table>
</div>
</form>
Reply With Quote
  #6  
Old 10-19-2005, 04:21 PM
herilane's Avatar
herilaneWebbrowser Frames herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

You should be able to use the code I posted above to click the button = submit the form. See if that works first, then we'll tackle the spreadsheet itself.

If you're only writing this for yourself, one easy way to solve this would be to change your settings so that the Excel file opens in Excel and not IE. Then it would be (relatively) easy to save it. If it opens in IE, I don't know if it's possible at all.
Reply With Quote
  #7  
Old 10-19-2005, 04:53 PM
homerjay7 homerjay7 is offline
Newcomer
 
Join Date: Oct 2005
Posts: 19
Default

Yes, I can submit it fine. I changed my .xls options like your link mentioned. Now, if I go to the site and click Submit, an IE window opens while it's downloading from the site, then Excel opens with the file. How would I go from there, getting the file saved?

This will probably only be on my computer, and will kick off on its own in the mornings or something, so it will work for now until we come up with a better solution to doing the whole process (not even using customer's websites to get Excel reports, etc.). I really appreciate your help.
Reply With Quote
  #8  
Old 10-20-2005, 03:00 PM
herilane's Avatar
herilaneWebbrowser Frames herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

OK, here's a quick example of Excel automation.
Code:
Imports Microsoft.Office.Interop '---------------- 'GetObject gets a reference to an existing Excel object, and will throw an exception if Excel isn't running Dim xlApp As Excel.Application = CType(GetObject(, "Excel.Application"), Excel.Application) Dim xlBook As Excel.Workbook = xlApp.Workbooks(1) xlBook.SaveAs ("C:\temp\test.xls") xlBook.Close(SaveChanges:=False) xlBook = Nothing xlApp = Nothing
You'll need to add a reference to the Microsoft Excel x.0 Object Library for this to work.
Reply With Quote
  #9  
Old 10-20-2005, 04:16 PM
homerjay7 homerjay7 is offline
Newcomer
 
Join Date: Oct 2005
Posts: 19
Default

Thanks a lot. That got it to save. I'm saving it as a .csv file, so I had to add:

xlBook.SaveAs("filename.csv", Excel.XlFileFormat.xlCSV)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Webbrowser Frames
Webbrowser Frames
Webbrowser Frames Webbrowser Frames
Webbrowser Frames
Webbrowser Frames
Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames Webbrowser Frames
Webbrowser Frames
Webbrowser Frames
 
Webbrowser Frames
Webbrowser Frames
 
-->