有没有办法可以使用标准WebBrowser或Awesomium WebControl在WPF应用程序中显示网页然后控制它。例如,我想加载google.com,在搜索中输入内容并单击搜索。我设法通过WebBrowser获取网页源,但我无法修改搜索文本框上的值。还有其他方法可以做到吗
像这样加载页面:
//private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
//{
// this.MyPage.Navigate("http://www.google.com");
//}
获取这样的HTML:
//private void MyPage_OnLoadCompleted(object sender, NavigationEventArgs e)
//{
// dynamic doc = MyPage.Document;
// dynamic htmlText = doc.documentElement.InnerHtml;
// string htmlstring = htmlText;
//bool search = htmlstring.Contains("lst-ib");
//var dom = MyPage.Document as HTMLDocument;
//if (dom != null)
//{
// var ec = dom.getElementById("lst-ib");
// SOMETHING TO ACCESS VALUE OF lst-ib AND CLICK SEARCH
//}
//}
我无法获得带有awesomium的html,也找不到任何关于如何操作的内容,所以感谢每一个帮助。
答案 0 :(得分:0)
var htmlDoc = ((MainWindow)Application.Current.MainWindow).webControl.Document as HTMLDocument;
if (htmlDoc != null)
{
var userid = htmlDoc.getElementById("userid") as HTMLInputElement;
var apikey = htmlDoc.getElementById("apikey") as HTMLInputElement;
if (userid != null && apikey != null)
{
userid.value = ((MainWindow)Application.Current.MainWindow).tbxApi.Text;
apikey.value = ((MainWindow)Application.Current.MainWindow).tbxVcode.Text;
var login = htmlDoc.getElementById("login") as HTMLFormElement;
if (login != null)
{
login.submit();
}
}}