0

I'm sure this request probably sounds familiar as I've seen a couple in the search results. I believe what I'm trying to do is unique and since no one else has asked it, I'm asking for help now.

I would like to have my application open a browser to a webpage that has a contact form. I would also like to include POST parameters. Is there any way to pre-populate a form with POST parameters without sending the actual request?

System.Diagnostics.Process.Start("IExplore.exe", "http://www.website.com/contactus.aspx?Subject=blah&Body=Test 1 2 3");

I tried the line above and it does load the page but the fields are not populated.

Any ideas?

snapplex
  • 851
  • 3
  • 13
  • 27

2 Answers2

1

You don't have many options here..

If the webpage populates the form based on the query string, then you could just include the form fields in the request, like in this example:

https://www.google.com.br/search?newwindow=1&site=&source=hp&q=how+to+fry+an+egg&oq=how+to+fry+an+&gs_l=hp.3.0.0l10.2234.4765.0.5734.14.14.0.0.0.0.188.1782.6j8.14.0.stareuni...0...1.1.32.hp..3.11.1234.DZuLJB2rmmg

If the webpage is yours, this is particularly easy because you could make it to behave this way.

Another option you would have is to use an automated interface test tool to do this through C#. Selenium is particularly good at it, and it's free. To understand how to use Selenium to automate forms filling, check this thread: How do I use Selenium in C#?

Community
  • 1
  • 1
Andre Pena
  • 56,650
  • 48
  • 196
  • 243
1

You are probably looking for something along the line of AutoIt or AutoHotKey. If you can't use these directly (as they will require a fair amount of integration) there are libraries that allow you accessing GetWindow/SetWindowText APIs from your c# code. I can refer you to source code of WASP, but I'm sure that you can find ready-made examples how to use interop to call the APIs you need.

The idea is that you fire up the browser page as you already did and then you walk the Window Tree (GetWindow) starting from desktop to find the fields that you want to fill in and then you fill them in (SetWindowText).

Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158