Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-04-2013
Perenquen Perenquen is offline
Miembro
 
Registrado: jul 2003
Posts: 27
Poder: 0
Perenquen Va por buen camino
automatización con webbrowser

Buenas a todos estoy intentando automatizar la descarga de algunos ficheros de un banco y para ello necesito rellenar los datos de distintos formularios

Por ahora conseguí hacer login como usuario pero para acceder a algunos campos estoy teniendo problemas. No se si es porque son componentes que están dentro de frames que a su vez estan dentro de frames.

Voy a poner un ejemplo que creo que así me aclararé mejor

En esta página para pulsar en el botón "buscar" utilizo en siguiente procedimiento (nombre := 'Buscar')

Código Delphi [-]
procedure TForm1.Clickar_boton(nombre : string);
var
  ovElements: OleVariant;
  i: Integer;
begin
  ovElements := WebBrowser1.OleObject.Document.forms.item(0).elements;
  for i := 0 to (ovElements.Length - 1) do
    begin
    if (ovElements.item(i).tagName = 'INPUT') and (ovElements.item(i).type = 'submit') and (ovElements.item(i).Value = nombre)  then
      begin
        ovElements.item(i).Click; 
      end;
    end;

end;

el valor "buscar" se puede obtener desde un navegador inspeccionando el elemento
<input type="submit" class="btnSearch" id="btnheadSearch" name="btnheadSearch" value="Buscar">

o bien mediante esta función que devuelve los componentes del webbrowser (aunque por lo que se ve no todos)

Código Delphi [-]
function TForm1.Obtener_componentes(ID : integer) : TstringList;
  function Get_FormByNumber(document: IHTMLDocument2;
    formNumber: integer): IHTMLFormElement;
  var
    forms: IHTMLElementCollection;
  begin
    forms := document.Forms as IHTMLElementCollection;
    if formNumber < forms.Length then
      result := forms.Item(formNumber,'') as IHTMLFormElement
    else
      result := nil;
  end;

  function Get_FormFieldNames(fromForm: IHTMLFormElement): TStringList;
  var
    index: integer;
    field: IHTMLElement;
    input: IHTMLInputElement;
    select: IHTMLSelectElement;
    text: IHTMLTextAreaElement;
  begin
    result := TStringList.Create;
    for index := 0 to fromForm.length do
    begin
      field := fromForm.Item(index,'') as IHTMLElement;
      if Assigned(field) then
      begin
        if field.tagName = 'INPUT' then
        begin
          // Input field.
          input := field as IHTMLInputElement;
          result.Add(input.name);
        end
        else if field.tagName = 'SELECT' then
        begin
          // Select field.
          select := field as IHTMLSelectElement;
          result.Add(select.name);
        end
        else if field.tagName = 'TEXTAREA' then
        begin
          // TextArea field.
          text := field as IHTMLTextAreaElement;
          result.Add(text.name);
        end;
      end;
    end;
  end;
var
  theForm: IHTMLFormElement;
  document: IHTMLDocument2;
  campos : TstringList;
begin
  campos := TStringList.create;
  document := WebBrowser1.Document as IHTMLDocument2;
  theForm := Get_FormByNumber(document,ID); // ID := 0 es el frame que contiene tanto el campo como el boton para buscar
  campos := Get_FormFieldNames(theForm);
  Freeandnil(Campos);
end;

Como dije hasta aquí todo parece ir bien. El problema lo tengo cuando intento acceder por ejemplo al botón "Entrar" del frame "formlogin" con ID 1
El botón se llama "Entrar" como se ve en el navegador
<input type="submit" id="txtAccess" name="txtAccess" class="generalBtn" value="Entrar">

Pero la función Obtener_componentes(ID : integer) con ID = 1 (ni con ninguno de los 5 valores posibles) me devuelve este componente, por lo que no puedo hacer click sobre él

Alguien me podría traer un poco de luz al dilema. El valor "entrar" no me aparece por ningún lado cuando recorro todos los frames del webbrowser y no se si es porque tendría que hacerlo recursivamente por si está dentro de otro frame.

Un saludo y gracias por leer el post, que al final me salió medio tocho.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
OLE Automatización de Excel r1d2m3 OOP 5 10-06-2011 18:59:45
Automatizacion Word con c++ Davervidto C++ Builder 12 08-06-2011 12:57:48
automatizacion Rave Report mjjj Impresión 3 08-07-2008 18:41:40
Automatización y Robótica MaMu Varios 1 08-07-2007 12:06:45
¿Es legal la automatización Web? Al González Debates 7 08-11-2006 16:23:25


La franja horaria es GMT +2. Ahora son las 09:42:40.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi