-1

I need to know how to fill an web form using Delphi XE3? I have a web form with user name and password, so how to fill it programmatically?

The page is http://batelco.com/portal see only two inputs user name and pass so how to fill and pass them ?

Arioch 'The
  • 15,799
  • 35
  • 62
Dreamer64
  • 923
  • 2
  • 13
  • 30
  • 1
    Perhaps you don't need to fill it but only to post it ? if the form does not include captcha or similar one-off protection, you can submit results without even loading the forms. – Arioch 'The Apr 26 '13 at 09:29
  • 2
    You should definitely not use a `TWebBrowser` control and fill the form programmatically if you only need to make a simple POST or GET HTTP request in the background. – Andreas Rejbrand Apr 26 '13 at 09:36
  • @AndreasRejbrand it seems that he starts the user login sequence. Given how rarely WWW pages use standard HTTP Auth, the page is probably makes some weird thing with UTLs or cookies or hidden forms or god knows what. In this circumstances POSTing login/password would not be hard, but understanding how the authentication was made and should be conveyed to later pages would be a separate and rather complex question. So, loading the page would probably be required thing, into MSIE like MS does or some another engine, but still. – Arioch 'The Apr 26 '13 at 09:45
  • the web page I'm trying to use dose not have any captcha, it's my ISP web page a basic user name and password to login to my account and check how much download I've used, so I'm trying to make and application which logs automatically and display the used downloads, that's it – Dreamer64 Apr 26 '13 at 11:04
  • Can you include the HTML code for the login form in your question? The solution depends on the authentication method, so this would be very helpful. – mjn Apr 26 '13 at 11:24
  • here u go the page is http://www.batelco.com/portal/ see only two inputs user name and pass so how to fill and pass them ? – Dreamer64 Apr 26 '13 at 11:31
  • See this for additional hints about sending data to ASP forms programmatically: http://stackoverflow.com/questions/10338763/howto-deal-with-cryptic-hidden-values-for-asp-net-viewstate – mjn Apr 26 '13 at 11:40
  • @MS when you add more detail - do it in question itself, not hidden deep behind many comments! – Arioch 'The Apr 26 '13 at 12:48

2 Answers2

1

Using Internet Direct (Indy) HTTP client class, you can submit form values to the server using HTTP POST.

The Indy HTTP client will also receive and store cookies which the server sends with its response, if an instance of the TIdCookieManager class has been assigned to the IdHTTP client component.

HTTP cookies are required by many secure web applications when the client makes further HTTP requests to other secured URL on the server. The Indy HTTP client then will send the cookies with the request (if a TIdCookieManager has been assigned to the IdHTTP client component).

So you could send a login POST request on the login URL, providing needed authentication information, and then send a GET request to the download statistics URL to retrieve its HTML.


Regarding your specific login form, which uses ASP, here is a question about programmatically sending POST requests: HowTo deal with cryptic hidden values for ASP Net (__VIEWSTATE)

Community
  • 1
  • 1
mjn
  • 36,362
  • 28
  • 176
  • 378
  • The person cannot even understand whioch page is the actual login form, and you suggest him cross-domain cookies handling and composite cross-domain pages manual parsing. While that should be most effective way, i don't think he would be able to do it. – Arioch 'The Apr 26 '13 at 13:04
  • @Arioch'The I did not mention or suggest "cross-domain cookies" handling anywhere – mjn Apr 26 '13 at 14:01
  • you do not, but that page uses login form fro mquite different domain, the cookie set during login would have to be used on the original domain most probably – Arioch 'The Apr 26 '13 at 16:22
  • @Arioch'The for session identification (and this is what the login form needs on the server side), cross domain cookies are the least I would probably expect - how will the servers exchange the session id in a cookie and correlate it with the user? So I think that the login form and the authenticated (secured) resources reside on the same server in the same domain. – mjn Apr 30 '13 at 12:48
  • you're hopefully correct. If all the extra services are made via FRAME/IFRAME. However i remember domains like borland.com/borland.ru or todays google.com/google.ru – Arioch 'The Apr 30 '13 at 13:00
0

This article shows how to get and set properties of named elements.

You should get and set value properties. What ID's would form elements have depends upon your page.

Check if Element with ID has a value


This article while asked "how to read" also describes both how to get values and how to set them. Afterall if you can do A := B (read value), then you probably can also do B := A (set value).

read content in webbrowser input field


Now, that the page URL is given in the question we can click on the right top corner login-form elements in WWW browser with right button, and choose "Inspect element" to see its sources. Or, if browser is not modern and does not have Inspect command on menu, we can use another commend, like View page source and find form in the sources of the whole page. For example one of those elements is

<input name="txtUsername" type="text" maxlength="15"
 id="txtUsername" tabindex="1" class="inpu-field" onfocus="txtfocus();"
 onblur="txtblur();" style="color: gray; background-image: none;">

Thus we know know the ID of 1st element of form, whose "value" attribute we need to get(read) or set(write). Links above show how to do it, given the known ID.

BTW, you given your page wrong, the real page is https://www.e-services.com.bh/Eservices/login_batelco.aspx

What about your original page, it just does not work with MSIE6 that is TWebBrowser in default mode - for compatibility with all the written applications using Microsoft ActiveX component. See https://i.stack.imgur.com/i3vAm.jpg

If can use Google Chrome instead of TWebBrowser. Or you can reach the ActiveX interface as one of TWebBrowser properties, and acquire new interface and turn off MSIE6-compatibility http://msdn.microsoft.com/en-us/library/aa752510.aspx

However, "how to make this page render in twebbrowser" is another, new question, not the question you asked here.


Actually, the only reason why i do not vote for closing this question as duplicate, is because none of articles above have "set" or "write" or "fill" in their title, so finding them was a bit harder than trivial.


But if the page is not mutating on load and does not have some one-time protection like CAPTCHA or unique form hash-codes, then you can post all the values with single HTTP request without even loading the form.

Community
  • 1
  • 1
Arioch 'The
  • 15,799
  • 35
  • 62
  • show me how ?? btw the part of the user name and password cannot be shown in the twebbrowser ! how to read it ! – Dreamer64 Apr 26 '13 at 12:04
  • If they "cannot be shown" then that is another question. If your user cannot see where to click and enter text - then you have nothing to read. Make a separate question how to load that page in Delphi+MSIE. Or you can use Delphi+Chrome or Delphi+THTMLViewer – Arioch 'The Apr 26 '13 at 12:18
  • if I use Internet Explorer it's there no problem, but it I use Delphi's twebbrowser it's not !! this is where the problem occur ! – Dreamer64 Apr 26 '13 at 12:25
  • then that is another problem, not how to read values after user entered them, but how to render this page in TWebBrowser so that user can do it. That is different question. Also try to check that page in MSIE6, i slightly recall by default TWebBrowser works in MSIE6 mode, not in modern mode, for the sake of compatibility. If your site is not compatible to MSIE6 - then perhaps that is the problem. Maybe it is http://msdn.microsoft.com/en-us/library/aa752510.aspx – Arioch 'The Apr 26 '13 at 12:43