0

GeckoFX Web ブラウザーを使用して、このように JavaScript を介して GeckoElement を渡すことは可能ですか?

WebBrowser.Navigate("javascript:void("+ele.DomObject+".onclick())");

JavaScript (これは正常に動作します) atm を介して DOM 要素を選択していますが、要素は c# にあります。

4

2 に答える 2

1

残念ながら、要素をそのように JavaScript に渡すことはできません。

ただし、WebBrowser.Navigate 呼び出しは不要であり、ページ変数が不必要に失われます。

完全を期すために、私はスニペットを投稿しました-この機会に長く巻き上げました;)-javascriptを挿入し、ブラウザをナビゲートして実行する必要なく、button.click()ハンドラーを介して自動化されたボタンクリックから呼び出します全て。

DOM.GeckoScriptElement script = Document.CreateElement("script").AsScriptElement();
script.Type = "text/javascript";
script.Text = "function doAlert(){ alert('My alert - fired by automating a button click on the [Automated Button]'); }";
Document.Body.AppendChild(script);

script = Document.CreateElement("script").AsScriptElement();
script.Type = "text/javascript";
script.Text = "function callDoAlert(id){ var el = document.getElementById(id); el.click(); }";
Document.Body.AppendChild(script);

DOM.GeckoInputElement button = Document.CreateElement("input").AsInputElement();
button.Type = "button";
button.Id = "myButton";
button.Value = "Automated Button";
button.SetAttribute("onclick", "javascript:doAlert();");

Document.Body.AppendChild(button);

DOM.GeckoInputElement button2 = Document.CreateElement("input").AsInputElement();
button2.Type = "button";
button2.Id = "myOtherButton";
button2.Value = "Press Me";
button2.SetAttribute("onclick", "javascript:document.getElementById('myButton').click();");

Document.Body.AppendChild(button2);

//uncomment to fully automate without the <webbrowser>.Navigate("javascript:.."); hack
//button2.click();

主にコントロールのGFXeビルドの使用に焦点を当てているため、このスニペットが直接役立つかどうかはわかりませんが、

WebBrowser.Navigate("javascript:hack.goesHere()"); 騙す。

于 2010-12-20T20:05:03.953 に答える
0

これは次の方法で実行できます。

WebBrowser.Navigate("javascript:void(document.getElementById('"+button.Id+"').click())");
于 2011-11-11T16:17:16.807 に答える