Delphi Twebbrowser更改文本框的值.
我在twebbrowser中更改文本框的值有些困难.我试过WebBrowser1.OleObject.Document.getElementById(‘verification_control_0′).value:=’mytext’;和其他一些方法,但它似乎不起作用.
网站代码: <div id="verification_control_0" class="verification_control"> <div class="smalltext"> What are the first 3 letters of our website's name?:<br /> <input type="text" name="register_vv[q][71]" size="30" value="" tabindex="6" class="input_text" /> </div> </div> 如果你能告诉我如何更改< input type =“text”中的值name =“register_vv [q] [71]”size =“30”value =“”tabindex =“6”class =“input_text” />我非常感激. 解决方法
试试这个:
procedure TForm1.Button1Click(Sender: TObject); var col: IHTMLElementCollection; el: IHTMLInputElement; begin col := (WebBrowser1.Document as IHTMLDocument3).getElementsByName('register_vv[q][71]'); if col.length <> 0 then begin el := col.item(0,0) as IHTMLInputElement; el.value := 'mytext'; end; end; 在IE8标准模式下, 因此,如果您的TWebBrowser使用IE7标准模式和以前的模式getElementById也应该工作: procedure TForm1.Button2Click(Sender: TObject); var el: IHTMLElement; inputElement: IHTMLInputElement; begin el := (WebBrowser1.Document as IHTMLDocument3).getElementById('register_vv[q][71]'); if Assigned(el) then if Supports(el,IID_IHTMLInputElement,inputElement) then inputElement.value := 'mytext'; end; 使用getElementsByName集合按NAME定位元素应该是首选解决方案. 编辑: WebBrowser1.OleObject.Document.getElementByID('register_vv[q][71]').Value:='tes??t'; 我非常确定OP没有测试你的代码(默认情况下应该可以工作,除非OP明确改变IE浏览模式),而是使用了getElementByID(‘verification_control_0’) – 这是一个DIV元素,并且没有支持方法值. (因此自动化对象不支持错误消息“方法’值”). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |