Stan
Stan

Reputation: 26501

Headless browser like selenium but which does not open the actual browser

I built simple application in C# that is posting new link to google+ account, however it is starting the actual browser itself. I'm fine with C#, Python, PHP languages, maybe even something else.

I cannot use C# WebClient class since many interactions are based on JS so I need to somehow emulate the browser.

This is my C# code for selenium so you can understand what I'm trying to achive.

static void Main(string[] args)
{
    IWebDriver driver;
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    driver = new FirefoxDriver();
    driver.Navigate().GoToUrl("https://accounts.google.com/ServiceLoginAuth");
    driver.FindElement(By.Name("Email")).SendKeys("MYEMAIL");
    driver.FindElement(By.Name("Passwd")).SendKeys("MYPASSWORD");
    driver.FindElement(By.Name("signIn")).Click();
    driver.Navigate().GoToUrl("https://plusone.google.com/_/+1/confirm?hl=en&url=http://site.com/");
    System.Threading.Thread.Sleep(10000);
    driver.FindElement(By.ClassName("e-U-a-fa")).Click();
    Console.WriteLine("Done!");
    Console.ReadLine();
}

Upvotes: 2

Views: 2536

Answers (3)

CBRRacer
CBRRacer

Reputation: 4659

There is a headless browser project that already exists but it doesn't support javascript called simplebrowser. If that is acceptable you could grab that browser project and then you would have to do some custom work on it. Set that browser to implement the IWebDriver interface in C#. The resolve all of the breaks. once you get it to compile then you should be able to instantiate the IWebdriver to a new SimpleBrowser.

IWebDriver driver = new SimpleBrowser();

I'm not saying that it wouldn't be some work but you would have a fully customizable headless browser that uses C# but is open sourced. Here's the source for the simple broswer.

https://github.com/axefrog/SimpleBrowser

Upvotes: 2

Niklas B.
Niklas B.

Reputation: 95288

That looks like a perfect use case for the Ruby library capybara-webkit(https://github.com/thoughtbot/capybara-webkit) or my own, small Python scraping library, dryscrape, which is based on the former :)

Both use the same C++ backend to create an in-memory, headless browser based on QtWebkit. I only tested it on Linux, though, but it should also be compile on Windows with some effort. People have done it with capybara-webkit, at least.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190907

You could use the web browser winforms control and inject scripting into that.

Upvotes: 0

Related Questions