Created
November 10, 2013 13:42
-
-
Save novalagoon/7398427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Awesomium.Core; | |
namespace AwesomiumNewTest | |
{ | |
class Google | |
{ | |
WebView m_view = null; | |
bool m_running = true; | |
bool m_finishedLoad = false; | |
public Google() | |
{ | |
m_view = WebCore.CreateWebView(1024, 768); | |
m_view.LoadingFrameComplete += onFinishLoading; | |
m_view.Source = "http://www.google.com".ToUri(); | |
} | |
public void update() | |
{ | |
while (m_running) | |
{ | |
WebCore.Update(); | |
if (m_finishedLoad) | |
{ | |
screenShot(); | |
runCommands(); | |
} | |
System.Threading.Thread.Sleep(1000); | |
} | |
} | |
static int mNr = 1; | |
public void runCommands() | |
{ | |
switch (mNr) | |
{ | |
case 1: | |
{ | |
string s = string.Format("document.evaluate(\"//input[@name='{0}']\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.value = \"{1}\";", "q", "test"); | |
m_view.ExecuteJavascript(s); | |
break; | |
} | |
case 2: | |
{ | |
string s = string.Format("document.evaluate(\"//button[@name='{0}']\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();", "btnK"); | |
m_view.ExecuteJavascript(s); | |
break; | |
} | |
default: | |
{ | |
m_running = false; | |
break; | |
} | |
} | |
mNr++; | |
} | |
public void screenShot() | |
{ | |
string fName = string.Format("test{0}.jpg", mNr.ToString()); | |
BitmapSurface bs = (BitmapSurface)m_view.Surface; | |
bs.SaveToJPEG(fName); | |
} | |
public void onFinishLoading(object sender, FrameEventArgs e) | |
{ | |
if(e.IsMainFrame) | |
m_finishedLoad = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/AlexP11223/7409349