Solved

WebBrowser, following a url.

Posted on 2003-10-21
1
148 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 125 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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