问题
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:
- open webpage in awesomium
- grab HTML to string (currently using: ExecuteJavascriptWithResult())
- parse string to HTML (currently using: "HTML Agility pack")
- do what I need to do (find elements, collection, etc.)
- 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