Page 1 of 1

## 13 Replies - 7624 Views - Last Post: 14 March 2012 - 07:38 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=194999&amp;s=001ae15b3e354f7f44950150c4270661&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Guest_Andrew*

Reputation:

Posted 14 October 2010 - 12:02 PM

I've been googling my brain out and cannot find a solution to my problem. I'm attempting to automate a process that would login to a website and then download a file by a given url. The only problem is that I can't figure out how to automate the login process to the jsp site. The site I'm tyring to login to is http://www.supplierlink.carrier.com. Any help in this area would be great. I've literally tried everything.

Is This A Good Question/Topic? 0

• Saucy!

Reputation: 6226
• Posts: 23,978
• Joined: 23-August 08

Posted 14 October 2010 - 12:11 PM

Well, you have to know the HTTP protocol for starters. You need to look at the source of the page and figure out all the form fields that need to be provided, and the page to which the form data is posted.

### #3 Guest_Andrew*

Reputation:

Posted 14 October 2010 - 12:20 PM

I do know the form fields to fill in. Here is a sample of code I came up with to automate this, but I couldn't get to work. I'm not even sure if this is the right way to go about it but it won't set the inner text of the elements when I try to assign it values.

        private void Web()
{
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}

private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{

WebBrowser web = sender as WebBrowser;

web.document.GetElementById("submit").InvokeMember("click");
}

private void wb_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = sender as WebBrowser;
string response = b.DocumentText;

StreamWriter sw = new StreamWriter(@"C:\Users\azwicker\Desktop\text.txt");

sw.Write(response);
sw.Close();

if (response.Contains("Sign out"))
{
}
}



### #4 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 4919
• Posts: 8,828
• Joined: 08-June 10

Posted 14 October 2010 - 12:26 PM

Let me show you a snippet from another project I did requiring that I pass values to a website:

public static Response UploadImage(Image image)
{
...
using (WebClient wc = new WebClient())
{
var fields = GetFields(image);
try
{
...
}
catch (Exception exc)
{
res.Exception = exc;
}
}
...
}

private static NameValueCollection GetFields(Image image)
{
NameValueCollection res = new NameValueCollection();
return res;
}


This will POST all values in the NameValueCollection to the provided URL.

Now, it may be that you have to maintain a state via a cookie or something like that. That will get more complicated.

This post has been edited by insertAlias: 14 October 2010 - 12:27 PM

• Saucy!

Reputation: 6226
• Posts: 23,978
• Joined: 23-August 08

Posted 14 October 2010 - 12:28 PM

Oh, you're using a WebBrowser component. I'll bow out of this then, as I'm not all that familiar with it.

I will say that when you say "it doesn't work", that doesn't give us a lot to go on. Be specific as to what is not working.

### #6 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 4919
• Posts: 8,828
• Joined: 08-June 10

Posted 14 October 2010 - 12:32 PM

I'll also say I don't know anything about using a WebBrowser. That's a UI control, not really something for automation, like a WebClient or an HttpWebRequest/Response.

### #7 zwickz711

Reputation: 1
• Posts: 8
• Joined: 14-October 10

Posted 14 October 2010 - 12:35 PM

Well I'm not exactly sure that the way I'm going about this is correct. I'm not familiar with navigating through websites programmatically... But it's not working the way I think it would simply by not being able to set the values of the inner text of the HTML elements that i need to set. The elements inner text just stay at the value of null.

InsertAlias, thanks for your post. I'll see what I can do with that.

This post has been edited by zwickz711: 14 October 2010 - 12:37 PM

• Saucy!

Reputation: 6226
• Posts: 23,978
• Joined: 23-August 08

Posted 14 October 2010 - 12:43 PM

I don't think you want to set the innertext. I think instead you should be getting those as an HtmlInputElement and setting the value.

But that's strictly a wild-ass guess

### #9 zwickz711

Reputation: 1
• Posts: 8
• Joined: 14-October 10

Posted 14 October 2010 - 01:18 PM

JackOfAllTrades, on 14 October 2010 - 11:43 AM, said:

I don't think you want to set the innertext. I think instead you should be getting those as an HtmlInputElement and setting the value.

But that's strictly a wild-ass guess

lol. Ill try that too. Thanks for your help.

### #10 zwickz711

Reputation: 1
• Posts: 8
• Joined: 14-October 10

Posted 18 October 2010 - 01:25 PM

So I got the login to work, with the HTMLInputElements as mentioned before. The only problem now is downloading the file automatically. When I try to navigate to the url of the file download a save/open dialog box appears asking me what I want to do. I'm wondering if theres a way to bypass that and just download it automatically by using the WebBrowser control?

### #11 Curtis Rutland

• （╯°□°）╯︵ (~ .o.)~

Reputation: 4919
• Posts: 8,828
• Joined: 08-June 10

Posted 18 October 2010 - 02:26 PM

According to some of the things I've read, you simply won't be able to do this. It's a security issue. Remember, you're basically using an instance of Internet Explorer when you're using the WebBrowser control.

Just one forum that mentions this:

Anyway, I'd suggest against using the WebBrowser and use the WebClient object. It's different, you'll have to re-figure it out, but you can download a file without any dialog box using it.

Also, you could try using HttpWebRequest. That works as well. More manual work, but more fine control.

### #12 zwickz711

Reputation: 1
• Posts: 8
• Joined: 14-October 10

Posted 19 October 2010 - 05:20 AM

insertAlias, on 18 October 2010 - 01:26 PM, said:

According to some of the things I've read, you simply won't be able to do this. It's a security issue. Remember, you're basically using an instance of Internet Explorer when you're using the WebBrowser control.

Just one forum that mentions this:

Anyway, I'd suggest against using the WebBrowser and use the WebClient object. It's different, you'll have to re-figure it out, but you can download a file without any dialog box using it.

Also, you could try using HttpWebRequest. That works as well. More manual work, but more fine control.

That's exactly what I had found too but wanted to make sure. I've considered using the others but I'm unsure of how to manipulate the html of the page in order to login to the page to access the file download url. Any ideas there?

This post has been edited by zwickz711: 19 October 2010 - 05:21 AM

### #13 zwickz711

Reputation: 1
• Posts: 8
• Joined: 14-October 10

Posted 21 October 2010 - 12:00 PM

I finally figured out a way to automate this process. There is a tool called watiN that will automate the process through IE. This was able to handle the open/save file dialog box. Here is the code I used through it to automate my process....

            IE ie = new IE("urltologinto");
//ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);

//html tags to find by name

ie.WaitForComplete();



### #14 manramro

Reputation: 0
• Posts: 1
• Joined: 10-March 09

Posted 14 March 2012 - 07:38 AM

zwickz711, on 21 October 2010 - 12:00 PM, said:

I finally figured out a way to automate this process. There is a tool called watiN that will automate the process through IE. This was able to handle the open/save file dialog box. Here is the code I used through it to automate my process....

            IE ie = new IE("urltologinto");
//ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);

//html tags to find by name

ie.WaitForComplete();