interacting with awesominum webcontrol

对着背影说爱祢 提交于 2019-12-08 04:11:08

问题


Can you find HTML elements in awesomium webcontrol to do the further processing?

For example, I can find necessary element (or even element collection) in Watin using:

Link playButton = myie.ElementOfType<Link>(Find.ById("myid")); // find link (<a>)
Div test = myie.Div(Find.ById("audio")); // find div (<div>)

When found - you can extract multiple properties of that element

string classname = playButton.ClassName; // alternatively -> inner text, link, id, class and all bucket of other properties

How do I do it in awesomium? Does it have built-in DOM parser to operate with website controls? (divs, links, tables, etc..)

So far I could only find javascript execution command but that's not what I'm looking for..

Additionally, I'd like to know how to save webpage's HTML to string (in awesomium)?

string mysite = webControl1.SiteHTML.ToString(); // something like this
// instead of
string mysite = webControl1.ExecuteJavascriptWithResult("document.documentElement.outerHTML").ToString();

EDIT: explaination

It looks like awesomium doesnt support HTML element parsing natively, so my backup plan is following:

  1. open webpage in awesomium
  2. grab HTML to string (currently using: ExecuteJavascriptWithResult())
  3. parse string to HTML (currently using: "HTML Agility pack")
  4. do what I need to do (find elements, collection, etc.)
  5. execute JS command in awesomium based on previous step results

All of this would be easier if awesomium had DOM support.. but.. well..


回答1:


With regards to the "How can I get the HTML" question, I seem to recall using a semi-hacky way of doing this when I ran into this problem:

var control = <some awesomium WebControl instance>;
control.SelectAll();
control.CopyHtml();
var html = Clipboard.GetText();



回答2:


And how about a JS trick?

public string GetHTML(WebControl control)
{
          return control.ExecuteJavascriptWithResult("document.getElementsByTagName('html')[0].outerHTML");

}

Cheers!




回答3:


Yes we can found html element to do further processing on. For example;

    dynamic document = (JSObject)webControl.ExecuteJavascriptWithResult("document");

using (document)
                {
                    try
                {
                    dynamic email = document.getElementById("email");
                    dynamic password = document.getElementById("password");

                    if (email == null && password == null)
                        return;

                    using (email)
                    {
                        email.value = "abc@msn.com";
                    }

                    using (password)
                    {
                        password.value = "password";
                    }
                }
                catch (Exception)
                {

                }

            }

It is the way i found the htmlInputElement and i have tested it and it works for me.



来源:https://stackoverflow.com/questions/14761334/interacting-with-awesominum-webcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!