Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WebBrowser, following a url.

Posted on 2003-10-21
1
Medium Priority
?
157 Views
Last Modified: 2010-04-05
Hey,

Is it possible to let your application simulate a click on a link on a site in a WebBrowser component. The first part of the url it has to click on is unique but the other part does change everytime you surf though.

Thanks in advance!
0
Comment
Question by:JuicyJ
1 Comment
 
LVL 3

Accepted Solution

by:
Peter_ earned 500 total points
ID: 9594320
Import typelibrary MSHTML.pas from MSHTML.dll

With this typelibrary you can then seach your document to find the right MSHTML Element.

First get hold of the IDocument3 interface, by typecasting Webbrowser1.Document:

var
  MyDocument: IDocument3;

MyDocument := (Webbrowser1.Document as IDocument3);

If you know the name of the element that has the link, you might use:

var
 MyElement: IHTMLElement;

MyElement := (MyDocument.getElementsByName('NameOfMyElement').item(0, '') as IHTMLElement);

MyElement.Click might then do the trick? If not, then try typecast to some subclass. Make sure to have the typecast within try/except as it might fail. I have not tried to navigate links, just posted forms.
Perhaps if only you can get hold of the right URL, then Webbrowser1.Navigate('...') would work as well.

If you don't know the name of the element, you might loop the MyDocument.all collection looking for a possible match:

var
 MyCollection: IHTMLElementCollection;

MyCollection := (MyDocument.all as IHTMLElementCollection);

for i:=0 to MyCollection.Count-1 do
 MyElement := (MyCollection[I] as IHTMLElement);
 ...

You may also try using MyDocument.getElementsByTagName(const v: WideString) to get a collection of all elements of a specific type.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

926 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