フォーラム


ゲスト  

ようこそ ゲスト さん。このフォーラムに投稿するには 登録が必要です。

ページ: [1] 2
トピック: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
a23
メンバー
投稿数: 33
IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/10/31 19:47 Tue

941_ウェブページのテキスト入力とボタンクリック等
http://mrxray.on.coocan.jp/Delphi/plSamples/941_IEObject_InputClick.htm#01
を参考にさせていただいております。

Delphiから、下記のような、フォームにも、文字列出力は可能でしょうか?

——————————————————————————

<html>
<head>
<dd><input type=text class=w300 placeholder=例)日本太郎 data-key=user.name1 maxlength=20>
<label data-key=user.company_title id=label_company_title>様</label>
<span class=w120 id=datalist_company_title style=position:relative name=名称></span>
<label class=bytelimit>(全角10文字まで)</label>
<div class=error_msg data-key-error=user.name1></div>
<div class=error_msg data-key-error=user.company_title></div></dd>

<dt>電話番号<span class=must>必須項目</span></dt><dd><input type=text class=w150 id=c_tel1 placeholder=例)06-1234-4567 data-key=user.company_telephone_display maxlength=15>
</body>
</html>

 
——————————————————————————
サンプルプログラムを添付させていただきます。
(Delphi10.2 Windows10)
http://www.workword.co.jp/files/5815/0944/6746/ie_input_1.zip
——————————————————————————
実行ファイルで、青枠はOK、赤枠はエラーとなります。

<dd>とかHTMLが、よく理解できていないだけなのかもしれませんが、ご存知の方がおられましたら、ご教授ください。

毛利 春幸
メンバー
投稿数: 25
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/01 18:53 Wed


動きました。
まずShell32_TLBなものがあったので削除して
SHDocVwのTShellWindowsを使いました。


var
f_sw_: TShellWindows;
IEObj : InternetExplorer;
begin
f_sw_ := TShellWindows.Create(nil);
IEObj := (f_sw_.Item(f_sw_.Count-1) as InternetExplorer);

end;


html側のソースを変更


<html>
<head>
<dd><input type=text class=w300 placeholder=例)日本太郎 data-key=user.name1 maxlength="20" id=name1>
<label data-key=user.company_title id=label_company_title>様</label>
<span class=w120 id=datalist_company_title style=position:relative name=名称></span>
<label class=bytelimit>(全角10文字まで)</label>
<div class=error_msg data-key-error=user.name1></div>
<div class=error_msg data-key-error=user.company_title></div></dd>

<dt>電話番号<span class=must>
必須項目</span></dt><dd>
<input type=text class=w150 id=c_tel1 placeholder=例)06-1234-4567 data-key=user.company_telephone_display maxlength=15>
</body>
</html>
au
メンバー
投稿数: 16
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/02 09:17 Thu

idやname属性の無いって事なので、毛利さんの方法では意図と違う感じなのかと。
基本的には参照されてる「941_ウェブページのテキスト入力とボタンクリック等」ページ内の「04_name 属性も id 属性もないボタンのクリック」を参考にすれば出来るはずです。
IHTMLElementのgetAttributeでdata-key属性を取得出来るみたいなのでそこで判定すれば良いかと。


var
・・・
TagName : OleVariant;
iDisp : IDispatch;
iElementCollection : IHTMLElementCollection;
iElement : IHTMLElement;
i : integer;
Attr : string;
begin

LabeledEdit1.Text:='06-1234-5678';
LabeledEdit2.Text:='なまえ';
try
//IHTMLDocument2インタフェイスのオブジェクトを取得
Doc2 := IEObj.Document as IHTMLDocument2;
TagName := 'INPUT';
IDisp := Doc2.all.tags(TagName);
if Assigned(IDisp) then
begin
IDisp.QueryInterface(IID_IHTMLElementCollection, iElementCollection);
if Assigned(iElementCollection) then
begin
for i := 0 to iElementCollection.length - 1 do
begin
iDisp := iElementCollection.item(i, 0);

iDisp.QueryInterface(IID_IHTMLElement, iElement);
if Assigned(iElement) then
begin
Attr := iElement.getAttribute('data-key',0);
if SameText(Attr, 'user.name1') then
begin
iInputElement := iElement as IHTMLInputElement;
iInputElement.value := LabeledEdit2.Text;
end else if SameText(Attr, 'user.company_telephone_display') then
begin
iInputElement := iElement as IHTMLInputElement;
iInputElement.value := LabeledEdit1.Text;
end;
end;
end;
end;
end;
end;
毛利 春幸
メンバー
投稿数: 25
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/02 10:46 Thu

すいません。
Facebookメッセージで内容を頂いていたので、それとごっちゃになってました。
クラス名からでも取れますね。


iInputElement := (IEObj.Document as DispHTMLDocument).querySelector('input.w300')as iHTMLInputElement;
iInputElement.value := LabeledEdit2.Text;
a23
メンバー
投稿数: 33
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/04 11:58 Sat

auさん、コード添付、ありがとうございます、バッチリです、Web/HTMLともに、詳しくないので、理解するのに、時間がかかり、ご返信が遅れましたが、大変勉強になりました。

毛利さん、ご回答、ありがとうございます、input.w300 のw300って、どういう内容でしょう?

a23
メンバー
投稿数: 33
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/08 08:51 Wed

Windows7 + IE11で、
Interface はサポートされていません.
となりました。

管理者権限でコマンドプロンプトを開いて、
「regsvr32 actxprxy.dll」 と打ち込んで再起動したら直りました。
という、記事を見つけたので、実行しました

が、結果、解消せず。

対処方法をご存知の方が、おられましたら、ご教授ください。

a23
メンバー
投稿数: 33
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/09 09:22 Thu

Delphiのエラーなので、Delphi Interface はサポートされていませんでググってみて、

RAD Studio(Delphi/C++Builder) XE6 Update1 でリソースDLLウィザードを実行すると「Interface はサポートされていません」のエラーが表示される
http://support.embarcadero.com/jp/article/44157

を試してみようと、思いましたが、XE6 用なので、断念。

au
メンバー
投稿数: 16
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/10 11:05 Fri

私の環境だとWin7+IE11で普通に動いてるのでなんとも良く判らない状態ですが。
エラーについては、コードの中のインターフェースの取り出し又はプロパティ・メソッドへのアクセス部分で出てると思うので、どこでエラーが出ているのかコードで示して貰わないと回答も付かないかと思います。

a23
メンバー
投稿数: 33
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/15 16:27 Wed

auさん、ありがとうございます。
私も動作していたように、思っていたのですが、新規にWindows7をクリーンインストールした機器で、テストしていた時に、エラー表示がでました、ソースを示せるように、準備させていただきたいと、思います。

a23
メンバー
投稿数: 33
Re: IDや名前がない、HTMLフォームにも、文字列入力は可能でしょうか?
on: 2017/11/15 18:59 Wed

http://mrxray.on.coocan.jp/Delphi/plSamples/941_IEObject_InputClick.htm#00

01_掲示板への文字列入力とボタンクリック – name 属性使用
より

添付コードで、
http://www.workword.co.jp/files/1415/1074/0113/mrxray_01.zip

値のセットと送信
を押すと、Windows7でエラーとなり、Windows10では、動作します。

ページ: [1] 2
WP Forum Server by ForumPress | LucidCrew
バージョン: 1.7.5 ; ページロード: 0.053 sec.