AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Webbrowser OleObject - Felder füllen

Ein Thema von gee21 · begonnen am 9. Apr 2013 · letzter Beitrag vom 10. Apr 2013
Antwort Antwort
Seite 1 von 3  1 23      
gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#1

Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 21:59
Hallo
Weiss jemand von euch warum ich diese 2 Felder nicht ausfüllen kann? Ist das nicht HTML? Oder mache ich mal wieder etwas falsch?

Feld1
Code:
<textarea id="message" name="message" style="width: 100%; overflow=auto;" tabindex="2" onkeypress="sms_message_change(this.form)"
Feld2:
Code:
        <textarea id="recipient" name="recipient" class="wickEnabled" style="width: 100%;" tabindex="1" onclick="hideErrorBlock();" onblur="countRecipients()" rows="2">
ich versuche es so auszufüllen:
webbrowser1.oleobject.document.forms.item(1).elements.item('message').value := memo1.text; (Item0-5 hab ich mal durchprobiert da ich nicht genau wusste wo die Felder genau liegen)

(Ganzer Homepage Code)
Delphi-Quellcode:
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript" />



<script type="text/javascript">
<!--

function convertRecipient(recipient) {

   //remove all non digit numbers but not +
   recipient = recipient.replace(/[^\d|^\+]+/g, "");
   
   if (recipient.length >= 3) {
      //IF first char=0 and 2nd not 0 THEN replace 0 by +41
      if (recipient.match("^0[^0]\d+")) {
         recipient = recipient.replace("^0", "+41");
      }

      
      //IF first and 2nd char=0 THEN replace 00 by +
      if (recipient.match("^00\d+")) {
         recipient = recipient.replace("^00", "+");
      }

   }

   return recipient;
}

function countRecipients(){

   var tmprecipients = document.getElementById('recipient').value
   var arraySpitter = tmprecipients.split(",");
   contactCounter= arraySpitter.length;
   if(contactCounter>10){
      document.getElementById('recipientsWarningTR').style.display = '';
   }

   else{
      document.getElementById('recipientsWarningTR').style.display = 'none';
   }

}

function addRecipient(recipientMsisdn, recipientName) {


   formatedRecipient= recipientName+" <"+convertRecipient(recipientMsisdn)+">";
   
   if(document.getElementById('recipient').value.length==0){
      document.getElementById('recipient').value=formatedRecipient;
   }

   else{
      document.getElementById('recipient').value=document.getElementById('recipient').value+", "+formatedRecipient;
   }


   countRecipients();
}

//-->
</script>

<link rel="stylesheet" href="/mip/ext/css/content.css" type="text/css" media="screen,projection" charset="utf-8" />
<link rel="stylesheet" href="/mip/ext/css/general.css" type="text/css" media="all" title="no title" charset="utf-8" />
<link rel="stylesheet" href="/mip/ext/css/screen.css" type="text/css" media="screen,projection" charset="utf-8" />
<link rel="stylesheet" href="/mip/ext/css/header.css" type="text/css" media="screen,projection" charset="utf-8" />
<link rel="stylesheet" href="/mip/ext/css/images.css" type="text/css" media="all" charset="utf-8" />
<link rel="shortcut icon" href="/mip/ext/img/favicon.ico" type="image/gif" media="all" />
<link rel="icon" href="/mip/ext/img/favicon.ico" type="image/gif" media="all" />
<!--[if IE]>
  <link rel="stylesheet" href="/mip/ext/css/screen_ie.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->
<!--[if lt IE 7]>
    <link rel="stylesheet" href="/mip/ext/css/screen_ie6.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->
<!--[if lt IE 6]>
    <link rel="stylesheet" href="/mip/ext/css/screen_ltie6.css" type="text/css" media="screen" charset="utf-8" />
<![endif]-->

<STYLE TYPE="text/css">
<!--
BODY {margin: 0;}
INPUT {border: 1px solid #C1B2B4;}
TEXTAREA {border: 1px solid #C1B2B4;}
textarea.error {
  background-color:#FCE5F1;
  color:black;
}

.radio_b {
  border: none !important;
  vertical-align: middle !important;
  padding-left: 10px;
  padding-right: 2px 2px 2px 0px;
}

.attachment_b {border: 1px solid #C1B2B4 !important;}
.attachment_b_opera {border: none !important;}

.accordion h2 {
  background-color:#E0CED0;
  padding:0pt;
  margin:0pt;
  cursor: pointer;
}

.accordion h2 span {
  padding:0px;
  margin:0pt;
}

.accordion h2 span img {
  float:right;
  margin:0.4em 0.4em 0pt 0pt;
  padding-right:0.4em;
}

.contacts div {
  line-height:2.0em;
  padding-left:0.4em;
}

.header {
  padding-bottom:0.5em;
  padding-top:0.5em;
}

.contact_item div {
  display: inline;
  cursor: pointer;
}

.button div {
  display:table-cell;
}

 
* html .button {
  display:inline-block;
}


.pg-normal {
   font-weight: normal;
}

 
.pg-selected {
   font-weight: bold;
}

-->
</STYLE>

<title>SMS-/MMS-Sender</title>

   
   <script type="text/javascript" language="JavaScript" src="/mip/ext/js/paging.js"></script>
   
   
   <script type="text/javascript" language="JavaScript" src="/mip/ext/js/motionpack.js"></script>
   
   
   
   <link rel="stylesheet" href="/mip/ext/css/wick.css" type="text/css" media="all" title="no title" charset="utf-8" />
   
   
   
   
   
   
   
   
   
      <script type="text/javascript" language="JavaScript">
         collection = ['""'];
      </script>
   
   
   
   <script type="text/javascript" language="JavaScript">
      contactCounter=0;
   </script>
   
   <script type="text/javascript" language="JavaScript" src="/mip/ext/js/wick.js"></script>
   
   
   
      <script type="text/javascript" language="JavaScript">
      //<!--
       function checkForm() {
          answer = true;

           if ( document.getElementById('mmsRB').checked) {
            document.getElementById('mmsAttachmentFileName').value = document.getElementById('mmsAttachment').value;
         }

       
          if (siw && siw.selectingSomething)
               answer = false;
          return answer;
       }
      //-->
   </script>
   

   
   
   
   
   <script type="text/javascript" language="JavaScript" src="/mip/ext/js/cookieTools.js"></script>


</head>

<body onload="onBodyLoadFn()" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">

   
   

  
  <p>
    
      <span id="errorBlock" class="error">
        
          <!-- SMS limit reached warning -->
       <div id="smsWarningTR" style="display:none;">
           Die maximale Nachrichtenlänge wurde erreicht.
       </div>
       </span>
     
  </p>

    <div id="recipientsWarningTR" class="error" style="display:none;">
        Es können maximal 10 Empfänger pro Nachricht ausgewählt werden.
    </div>

  

  

  <table border="0" width="100%" style="margin: 0pt">
    <!-- set up proportions -->
    <tr>
      <td width="30%"></td>
      <td width="50%"></td>
      <td></td>
    </tr>

    <!-- Here begins the form -->
    <form id="smsMmsSenderForm" method="post" action="/mip/dyn/login/smsMeinKonto?lang=de" enctype="multipart/form-data" onsubmit="return checkForm()">

    <!-- Sender -->
    <tr>
      <td>
        Absender
      </td>
      <td colspan="2">
         000000000
      </td>
    </tr>

    <!-- Recipient input text + message length counter -->
    <tr>
      <td>
        Empfänger
      </td>
      <td>
        <textarea id="recipient" name="recipient" class="wickEnabled" style="width: 100%;" tabindex="1" onclick="hideErrorBlock();" onblur="countRecipients()" rows="2"></textarea>
      </td>
      <td style="text-align: right">
        <div style="float:right;"><input style="width: 45px;" type="text" name="charsLeft" readonly="readonly" maxlength="10" tabindex="-1" value="160" /></div>
      </td>
    </tr>

    <!-- SMS / MMS Switch -->
    <tr>
      <td>
      &nbsp;
      </td>
      <td style="padding-left: 0px;" colspan="2">
      <div style="vertical-align: middle; padding: 4px 2px 0px 0px;">
           <input id="smsRB" name="type" class="radio_b" tabindex="-1" onclick="hideErrorBlock(); switchToSmsView(this.form);" type="radio" value="sms" checked="checked"/>SMS
           <input id="mmsRB" name="type" class="radio_b" tabindex="-1" onclick="hideErrorBlock(); switchToMmsView(this.form);" type="radio" value="mms"/>MMS
      </div>
      </td>
    </tr>

    <!-- Message textarea -->
      <tr>
        <td>
          Nachricht
        </td>
        <td colspan="2">
          <textarea id="message" name="message" style="width: 100%; overflow=auto;" tabindex="2" onkeypress="sms_message_change(this.form)" onkeyup="sms_message_change(this.form)" rows="4" cols="40"></textarea>
        </td>
      </tr>

    <!-- MMS Attachment -->
    <tr id="mmsAttachmentTR" style="display:none;">
      <td>
        Bild hinzufügen:
      </td>
      <td colspan="2">
        <input type="file" class="attachment_b" id="mmsAttachment" name="mmsAttachment" size="10" accept="image/*" tabindex="3">
        <input id="mmsAttachmentFileName" name="mmsAttachmentFileName" type="hidden" value=""/>
      </td>
    </tr>

    <!-- SMS counters -->
      <tr>
        <td>

        </td>

        <!-- Show [Send] button if it is possible -->
        <td colspan="2">
            
              <div class="submit">
                <button type="submit" value="send" name="send" tabindex="4">Senden</button>
                <input type="hidden" name="task" value="send"/>
                <input type="hidden" name="currentMsisdn" value="000000000000"/>
              </div>
            
        </td>
      </tr>
    </form>

    <!-- Show [Buy] button if it is possible -->
    <tr>
       <td>
          Guthaben
       </td>
      <td>
        <form method="post" action="">
            
        </form>
      </td>
      <td>
          Gratis 49
          Bezahlt 0
      </td>
    </tr>
    <tr>
       <td>
          Postausgang
       </td>
       <td>
          <div class="submit">
               <button type="submit" name="outbox" onclick="openOutboxWindow('/mip/dyn/login/outboxMeinKonto')">Gesendete Nachrichten</button>
          </div>
       </td>
    </tr>
  </table>

  <div class="accordion">
    <h2 class="header first-child" onClick="toggle('contacts','slide_toggle','/mip/ext/img/bus_plus_n.gif','/mip/ext/img/bus_minus_n.gif');">
      <span><img src="/mip/ext/img/bus_plus_n.gif" id="slide_toggle"/></span>
      <span style="padding-left:0.4em;">Adressbuch</span>
    </h2>

    <div class="contacts" id="contacts" style="overflow:hidden;">
        <div class="header">
          <form id="SMSCommand" method="post" action="/mip/dyn/login/smsMeinKonto?lang=de">
          
        
          <div style="float:left;width:70%;padding-left:0.3em;">
            <input id="contactName" name="contactName" class="normal" style="width:49%" tabindex="5" onfocus="if(this.value=='Hans Muster') {this.value='';this.style.color='#000000';}" onblur="if(this.value=='') {this.value='Hans Muster';this.style.color='#afafaf';}" type="text" value="" maxlength="50"/>
            <input id="contactMsisdn" name="contactMsisdn" class="normal" style="width:49%" tabindex="6" onfocus="if(this.value=='+41 76 123 45 67') {this.value='';this.style.color='#000000';}" onblur="if(this.value=='') {this.value='+41 76 123 45 67';this.style.color='#afafaf';}" type="text" value="" maxlength="50"/>
         <input id="editID" name="editID" type="hidden" value=""/>
            <script type="text/javascript">
            //<!--
            if(document.getElementById('contactName').className!="error") {
                document.getElementById('contactName').value = 'Hans Muster';
                document.getElementById('contactName').style.color = '#afafaf';
                document.getElementById('editID').value=''; 
            }

            if(document.getElementById('contactMsisdn').className!="error") {
                document.getElementById('contactMsisdn').value = '+41 76 123 45 67';
                document.getElementById('contactMsisdn').style.color = '#afafaf';
                document.getElementById('editID').value='';
            }

            //-->
            </script>
          </div>
          <div class="button">
            <div class="submit">
              <button type="submit" onclick="if(document.getElementById('contactName').value=='Hans Muster'){document.getElementById('contactName').value=''};if(document.getElementById('contactMsisdn').value=='+41 76 123 45 67'){document.getElementById('contactMsisdn').value=''};this.style.color='#000000';"
                value="addContact" name="add">hinzufügen</button>
              <input type="hidden" name="task" value="addContact"/>
              <input type="hidden" name="currentMsisdn" value="0765790054"/>
            </div>
          </div>
          </form>
        </div>
        
        <div id="pageNavPosition" class="pagenavigation" style="padding-left:1.2em;display:none;"></div>
        
        
    </div>
  </div>

  
  <script type="text/javascript">
  //<!--
    function editContact(id,msisdn,name){
       document.getElementById('contactName').value=name;
       document.getElementById('editID').value=id; 
       document.getElementById('contactName').style.color='#000000';
       document.getElementById('contactMsisdn').value=msisdn;
       document.getElementById('contactMsisdn').style.color='#000000'; 

     }

  
  
   var cookieName = 'mip_msg_dispContacts';
   
   var x = readCookie(cookieName)
   if (x == "1") {
      document.getElementById('contacts').style.display = "block";
      document.getElementById('slide_toggle').src = "/mip/ext/img/bus_minus_n.gif";
   }
 else if (x == "0") {
      document.getElementById('contacts').style.display = "none";
      document.getElementById('slide_toggle').src = "/mip/ext/img/bus_plus_n.gif";
   }
 else if (x == null) {
      //default setting
      document.getElementById('contacts').style.display = "none";
      document.getElementById('slide_toggle').src = "/mip/ext/img/bus_plus_n.gif";
      //create cookie
      createCookie(cookieName,'0',1000);
   }

   
   function toggle(objname,controller,img_open,img_close){
   
      if(document.getElementById(objname).style.display == "none") {
        //open
        document.getElementById(controller).src = img_close;
        slidedown(objname);
        createCookie(cookieName,'1',1000);
      }
 else if (document.getElementById(objname).style.display == "block") {
        //close
        document.getElementById(controller).src = img_open;
        slideup(objname);
        createCookie(cookieName,'0',1000);
      }
 else {
        return;
      }

      
      _IG_AdjustIFrameHeight();
   }
   
   function onBodyLoadFn() {
      if (window.opera) {
         var box = document.getElementById('mmsAttachment');
         box.className = 'attachment_b_opera';
      }

      
      switchToProperSmsMmsView();
   }
    
   function switchToProperSmsMmsView() {
      var thisform = document.getElementById('smsMmsSenderForm');
      if ( document.getElementById('mmsRB').checked) {
         switchToMmsView(thisform);
      }
 else {
         switchToSmsView(thisform);
      }

   }
      
   function switchToSmsView(thisform) {
      document.getElementById('mmsAttachmentTR').style.display = 'none';
      
      sms_message_change(thisform);
      
      _IG_AdjustIFrameHeight();
   }

   
   function switchToMmsView(thisform){
      document.getElementById('mmsAttachmentTR').style.display = '';

      sms_message_change(thisform);
   
      _IG_AdjustIFrameHeight();
   }

    
   function hideErrorBlock() {
      document.getElementById('errorBlock').style.display = 'none';
   }


    //get contact setting
   contactsPerPage = parseInt(queryString('up_contactsPerPage'));
   
   if (isNaN(contactsPerPage)) {
      contactsPerPage = 10;
   }

   
   var pager = new Pager('contact', contactsPerPage);
   pager.init('pageNavPosition');
   pager.showPageNav('pager', 'pageNavPosition');
   pager.showPage(1);
   
   function queryString(parameter) {
      var loc = location.search.substring(1, location.search.length);
      var param_value = false;
      
      var params = loc.split("&");
      for (i=0; i<params.length;i++) {
          param_name = params[i].substring(0,params[i].indexOf('='));
          if (param_name == parameter) {
              param_value = params[i].substring(params[i].indexOf('=')+1)
          }

      }
      if (param_value) {
          return param_value;
      }
 else {
          return false; //Here determine return if no parameter is found
      }

    }

      function openOutboxWindow (outboxUrl) {
          window.open(outboxUrl, "outbox", "menubar=no,status=no,titlebar=no,width=800,resizable=yes,scrollbars=yes");
      }

   
     function sms_message_change(thisform) {
       
        var maxLength;
        var msg = thisform.message.value;

      var newlineCount = msg.split("\n").length - 1;

      if (navigator.userAgent.indexOf("MSIE") > 0) {
         newlineCount = msg.split("\r\n|\r|\n").length - 1;
      }


      var charcount = msg.length + newlineCount;   
      
        if (document.getElementById('mmsAttachmentTR').style.display == '') {
           maxLength = 3000;
         thisform.charsLeft.value = maxLength - charcount;
         if(charcount > maxLength) {
               thisform.message.value = msg.slice(0, maxLength - newlineCount);
               return;
         }

        } else {
          maxLength = 160;
         var maxSms = 3;
         
         if (charcount > maxLength * maxSms) {
            thisform.message.value = msg.slice(0, (maxLength * maxSms) - newlineCount);   
            document.getElementById('smsWarningTR').style.display = '';
            _IG_AdjustIFrameHeight();
         }
 else {
            document.getElementById('smsWarningTR').style.display = 'none';
         }

         
         numberOfSms = Math.floor((charcount-1) / maxLength) + 1;
         
         if (numberOfSms == 0) {
            thisform.charsLeft.value = maxLength + " / 1";
         }
 else {
            thisform.charsLeft.value = (maxLength * numberOfSms - charcount) + " / " + numberOfSms;
         }

      }
       
        if((navigator.userAgent.indexOf("MSIE") == -1) && (navigator.userAgent.indexOf("Mozilla/4") != -1)) {
            thisform.message.blur();
            thisform.message.focus();
        }

    }
   //-->

      </script>

  
  
</body>
</html>
Robert

Geändert von gee21 ( 9. Apr 2013 um 22:09 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 22:14
webbrowser1.oleobject.document.forms.item(0).elements.item('message').value := .....
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#3

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 22:18
webbrowser1.oleobject.document.forms.item(0).elements.item('message').value := .....
Du meinst wegen der (0)?
Habe ich schon probiert. (0-5) bringt alles nichts.
Robert
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#4

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 22:22
Bei mir geht es damit es ist ja auch das erste Form
Code:
   <!-- Here begins the form -->
    <form id="smsMmsSenderForm" method="post" action="/mip/dyn/login/smsMeinKonto?lang=de" enctype="multipart/form-data" onsubmit="return checkForm()">
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#5

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 22:24
Ansonsten nimm einfach
WebBrowser1.OleObject.Document.getElementById('message').value := Memo1.text;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 22:31
Sehr merkwürdig. Bei mir geht beides nicht.

Erhalte immer folgende Meldung: (Bild im Anhang)

Ich warte auch extra schön bis die Homepage geladen ist und führe diesen Code extra Manuell per Button aus um ganz sicher zu gehen.
Miniaturansicht angehängter Grafiken
fehler.png  
Robert
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#7

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 22:52
Assigned(WebBrowser1) ist schon true ?
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#8

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 23:01
Assigned(WebBrowser1) ist schon true ?
Meinst du sowas?

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin

if Assigned(WebBrowser1)=true then showmessage('Vor');

WebBrowser1.OleObject.Document.getElementById('recipient').value := combobox1.Items[combobox1.ItemIndex]+edit3.Text;
WebBrowser1.OleObject.Document.getElementById('message').value := memo1.Text;

end;
Ich erhalte die Meldung "Vor" also Assigned =true
Robert
  Mit Zitat antworten Zitat
nahpets
(Gast)

n/a Beiträge
 
#9

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 23:04
Hallo,

die Fehlermeldung muss nicht zwingend in der Zeile auftreten, die Du uns gezeigt hast. Zeig doch bitte mal etwas mehr Quellcode.

Oder hilft Dir diese Funktion?
Delphi-Quellcode:
// ...HTML Formulare mit TWebBrowser automatisch ausfüllen lassen?
function WBFillForm(wb: TWebBrowser; sFieldName: string; sValue: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if wb.OleObject.Document.all.tags('FORM').Length = 0 then begin
    Exit;
  end;
  //count forms on document
  for I := 0 to wb.OleObject.Document.forms.Length - 1 do begin
    FormItem := wb.OleObject.Document.forms.Item(I);
    for j := 0 to FormItem.Length - 1 do begin
      try
        // when the fieldname is found, try to fill out
        if AnsiUpperCase(FormItem.Item(j).Name) = AnsiUpperCase(sFieldName) then begin
          FormItem.Item(j).Value := sValue;
          Result := True;
        end;
      except
        Exit;
      end;
    end;
  end;
end;
Der Aufruf müsste dann in etwa so aussehen:
Delphi-Quellcode:
  Application.ProcessMessages;
  while WebBrowser1.Busy do Application.ProcessMessages;
  while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages;
  if not WBFillForm(WebBrowser1,'message', Memo1.Text) then begin
    ShowMessage('Das Feld Message konnte nicht gefüllt werden.');
  end;
  Application.ProcessMessages;
  while WebBrowser1.Busy do Application.ProcessMessages;
  while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages;

Geändert von nahpets ( 9. Apr 2013 um 23:08 Uhr)
  Mit Zitat antworten Zitat
gee21

Registriert seit: 3. Jan 2013
199 Beiträge
 
Delphi 10.4 Sydney
 
#10

AW: Webbrowser OleObject - Felder füllen

  Alt 9. Apr 2013, 23:16
Hallo,

die Fehlermeldung muss nicht zwingend in der Zeile auftreten, die Du uns gezeigt hast. Zeig doch bitte mal etwas mehr Quellcode.

Oder hilft Dir diese Funktion?
Delphi-Quellcode:
// ...HTML Formulare mit TWebBrowser automatisch ausfüllen lassen?
function WBFillForm(wb: TWebBrowser; sFieldName: string; sValue: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if wb.OleObject.Document.all.tags('FORM').Length = 0 then begin
    Exit;
  end;
  //count forms on document
  for I := 0 to wb.OleObject.Document.forms.Length - 1 do begin
    FormItem := wb.OleObject.Document.forms.Item(I);
    for j := 0 to FormItem.Length - 1 do begin
      try
        // when the fieldname is found, try to fill out
        if AnsiUpperCase(FormItem.Item(j).Name) = AnsiUpperCase(sFieldName) then begin
          FormItem.Item(j).Value := sValue;
          Result := True;
        end;
      except
        Exit;
      end;
    end;
  end;
end;
Der Aufruf müsste dann in etwa so aussehen:
Delphi-Quellcode:
  Application.ProcessMessages;
  while WebBrowser1.Busy do Application.ProcessMessages;
  while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages;
  if not WBFillForm(WebBrowser1,'message', Memo1.Text) then begin
    ShowMessage('Das Feld Message konnte nicht gefüllt werden.');
  end;
  Application.ProcessMessages;
  while WebBrowser1.Busy do Application.ProcessMessages;
  while WebBrowser1.ReadyState <> READYSTATE_COMPLETE do Application.ProcessMessages;


Ok hier mal mein Quellcode, Dein Code habe ich übrigens getestet. Leider kommt die Meldung dass das Feld nicht ausgefüllt werden konnte.

Delphi-Quellcode:
var
  Form1: TForm1;

implementation

{$R *.dfm}

function WB_GetHTMLCode(WebBrowser: tembeddedwb; ACode: TStrings): Boolean;
var
   ps: IPersistStreamInit;
   ss: TStringStream;
   sa: IStream;
   s: string;
begin
   ps := WebBrowser.Document as IPersistStreamInit;
   s := '';
   ss := TStringStream.Create(s);
   try
     sa := TStreamAdapter.Create(ss, soReference) as IStream;
     Result := Succeeded(ps.Save(sa, True));
     if Result then ACode.Add(ss.Datastring);
   finally
     ss.Free;
   end;
end;



 function FillForm(WebBrowser: tembeddedwb; FieldName: string; Value: string): Boolean;
var
  i, j: Integer;
  FormItem: Variant;
begin
  Result := False;
  //no form on document
  if WebBrowser.OleObject.Document.all.tags('FORM').Length = 0 then
  begin
    Exit;
  showmessage('Exit');
  end;
  //count forms on document
  for I := 0 to WebBrowser.OleObject.Document.forms.Length - 1 do
  begin
    FormItem := WebBrowser.OleObject.Document.forms.Item(I);
    for j := 0 to FormItem.Length - 1 do
    begin
      try
        //when the fieldname is found, try to fill out
        if FormItem.Item(j).Name = FieldName then
        begin
          FormItem.Item(j).Value := Value;
          Result := True;
        end;
      except
        Exit;
      end;
    end;
  end;
end;





procedure TForm1.Button1Click(Sender: TObject);
begin

if Assigned(WebBrowser1)=true then showmessage('Vor');

WebBrowser1.OleObject.Document.getElementById('recipient').value := combobox1.Items[combobox1.ItemIndex]+edit3.Text;
WebBrowser1.OleObject.Document.getElementById('message').value := memo1.Text;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if combobox2.ItemIndex=2 then webbrowser1.Navigate('http://www.bern-web.ch/');

if combobox2.ItemIndex=1 then webbrowser1.Navigate('http://www1.sunrise.ch/SMS-Sender-cbBpfAqFI.RUoAAAEwinJTNyCu-Sunrise-Residential-Site-WFS-de_CH-CHF.html');
progressbar1.Position:=25;

end;

procedure TForm1.Button5Click(Sender: TObject);
begin
if form1.Height=322=false then form1.Height:=322 else form1.Height:=590;
end;

procedure TForm1.Edit4MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
 Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);

begin
Set8087CW($133F);
memo2.Lines.LoadFromFile(ExtractFilePath(Application.Exename)+'\config.txt');
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
 Perform(WM_SYSCOMMAND, $F012, 0);
end;



procedure TForm1.Memo1Change(Sender: TObject);
var
i: integer;
i2: integer;
begin
i:=memo1.MaxLength;
i2 := Length(Memo1.Text);

i:=i-i2;
edit4.Text:=inttostr(i);
if i<160 then edit1.Text:='3/3';
if i>160 then edit1.Text:='2/3';
if i>320 then edit1.Text:='1/3';
if i>479 then edit1.Text:='0/3';
end;

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
 Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TForm1.ProgressBar1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
 Perform(WM_SYSCOMMAND, $F012, 0);
end;


procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
i:integer;
begin

progressbar1.Position:=35;

if combobox2.ItemIndex=2 then begin
WB_GetHTMLCode(Webbrowser1, Memo2.Lines);
if FillForm(WebBrowser1, 'smsMessage', memo1.Text)=true then begin
 progressbar1.Position:=50;
  webbrowser1.Stop;
  FillForm(WebBrowser1, 'smsMessage', memo1.Text) ;
  FillForm(WebBrowser1, 'SMSEingabe', edit3.Text) ;
  if combobox1.ItemIndex=1 then FillForm(WebBrowser1, 'intlPrefix', '004176');
   if combobox1.ItemIndex=2 then FillForm(WebBrowser1, 'intlPrefix', '004177');
  if combobox1.ItemIndex=3 then FillForm(WebBrowser1, 'intlPrefix', '004178');
    if combobox1.ItemIndex=4 then FillForm(WebBrowser1, 'intlPrefix', '004179');

  webbrowser1.oleobject.document.forms.item(4).submit;
progressbar1.Position:=75;
  end else begin
      if progressbar1.Position=35 then begin
if edit7.Text='http://www.bern-web.ch/then begin
if pos('Heute wurden von Ihrer IP-Adresse',Memo2.Text) > 0 then label1.Caption:='Fehler: Limit erreicht! (IP oder Service wechseln)else label1.Caption:='Fehler: Service Down?';
label1.Visible:=true;
end;
end;
  end;
if edit7.Text='http://www.bern-web.ch/Bern/sms_ok/then begin
  Progressbar1.Position:=100;
webbrowser1.Navigate('www.google.com');
end;
  end;


///////////////// //////////////////////

if combobox2.ItemIndex=1 then begin

repeat;
Application.ProcessMessages;
Sleep(1);
until WebBrowser1.ReadyState=4;

try
webbrowser1.oleobject.document.forms.item(1).elements.item('LoginForm_Login').value := memo2.Lines[2];
except
end;

if webbrowser1.oleobject.document.forms.item(1).elements.item('LoginForm_Login').value =memo2.Lines[2] then begin
webbrowser1.oleobject.document.forms.item(1).elements.item('LoginForm_Password').value := memo2.Lines[3] ;
webbrowser1.oleobject.document.forms.item(1).submit;
end;

//Server1 ENDE
end;

end;



procedure TForm1.Webbrowser1DownloadComplete(Sender: TObject);
begin
edit7.Text:=webbrowser1.LocationURL;
end;

end.
Robert
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 3  1 23      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:23 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz