tMozillaBrowser preenchimento automatico

Delphi

22/06/2013

ola pessoal!

como preencher automaticamente no webbrowser do mozila(tMozillaBrowser)? usei o codigo abaixo e nao tá preenchendo:

webBrowser1.OleObject.document.all.item('campoTexto',0).value := edit1.Text;
WebBrowser1.OleObject.Document.all.Item('botao', 0).Click;

desde ja agradeço,


Adriano.

Adriano Pereira

Adriano Pereira

Curtidas 0

Respostas

Andre Peres

Andre Peres

22/06/2013

estou com a mesma dúvida aqui, não
encontro uma documentação com métodos equivalentes ao do Twebbrowser,
só encontro exemplos de navegadores simples que apenas navegam.
GOSTEI 0
Wagner Fonseca

Wagner Fonseca

22/06/2013

Bom dia.

Para implementar a atribuição de dados para dentro da página, é um pouco diferente:

Considerando o simples HTML:
...
<input type='text' name'texto' id='idTexto'></input>
...


function GetElementById(const Doc: IDispatch; const Id: string): IDispatch; 
var
  Document: IHTMLDocument2;     // IHTMLDocument2 interface of Doc
  Tags: IHTMLElementCollection;  // all tags in document body
  Tag: IHTMLElement;            // a tag in document body
  I: Integer;                   // loops thru tags in document body
begin
  Result := nil;

  // Check for valid document: require IHTMLDocument2 interface to it
  if not Supports(Doc, IHTMLDocument2, Document) then
    raise Exception.Create('Invalid HTML document');

  // Get all tags in body element
  Tags := Document.all;

  if not Assigned(Tags) then
    raise Exception.Create('Não foi possível encontrar uma tag <body> para esse documento!');

  // Scan through all tags in body
  for I := 0 to Pred(Tags.length) do
  begin
    // Get reference to a tag
    Tag := Tags.item(I, EmptyParam) as IHTMLElement;
    // Check tag's id and return it if id matches
    if AnsiSameText(Tag.id, Id) then
    begin
      Result := Tag;
      Break;
    end;
  end;
end;


A função acima é util para retornar o componente, ou melhor a tag html, do input que você quer inserir os dados.

para a utilização:
 
var
   inputTexto: IHTMLElement;
begin
   inputTexto:= getElementById(MozillaBrowser1.Document as IHTMLDocument2, 'idTexto') as IHTMLElement;
   if Assigned(inputTexto) then
     inputTexto.setAttribute('value', 'Aqui o valor string que eu quero inserir no input de texto!', 0);

end;
 



Espero ter ajudado


APROVEITO, para perguntar, se alguém sabe como executar o botão, ou submit de um form, dinâmicamente, lembrando que eu estou utilizando o componente TMozillaBrowser.

agradeço desde já a atenção prestada.
GOSTEI 0
POSTAR