Skip to content

Instantly share code, notes, and snippets.

@novalagoon
Created November 10, 2013 13:42
Show Gist options
  • Save novalagoon/7398427 to your computer and use it in GitHub Desktop.
Save novalagoon/7398427 to your computer and use it in GitHub Desktop.
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;
}
}
}
@AlexP11223
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment