Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use selenium with C

I can't find any information on if you can use selenium with C. Just C, not c#. Does anyone know if this is possible?

I tried searching on Google but all results that appear has "C#" in it and not "C".

like image 523
tablec1 Avatar asked Jan 07 '20 19:01

tablec1


1 Answers

From the official page of Selenium:

  • The core language-specific client drivers are:
  • Ruby
  • JavaScript
  • Java
  • Python
  • C#

However as per Selenium Official Home Page language bindings for other languages does exist but those projects are not supported, maintained, hosted, or endorsed by the Selenium project, which are as follows:

  • Selenium [Language: Go]
  • hs-webdriver [Language: Haskell]
  • wd [Language: JavaScript]
  • Selenium-Remote-Driver [Language: Perl]
  • php-webdriver [Language: PHP]
  • RSelenium [Language: R]
  • webdriver.dart [Language: Dart]

Solution

You could always write your WebDriver based tests in any of the core language e.g. Java/Python/C# and call the script from your C / C++ application.


Webdriver++

Webdriver++ is a C++ client library for Selenium Webdriver which you have to install and have the following feature support:

  • Chainable commands
  • Value-like objects compatible with STL containers
  • Header-only
  • Lightweight dependencies:
  • libcurl
  • picojson
  • Can be used with any testing framework
  • Linux, Mac and Windows
  • clang (3.4), GCC (4.6) and Visual Studio (2010)

An example:

#include <webdriverxx/webdriverxx.h>
using namespace webdriverxx;

int main() {
    WebDriver firefox = Start(Firefox());
    firefox
    .Navigate("http://google.com")
    .FindElement(ByCss("input[name=q]"))
    .SendKeys("Hello, world!")
    .Submit();
    return 0;    
}

@JimEvans in his comment clearly mentions:

If you really don't care that you're not running in a "real" browser, then directly consuming QtWebKit might be a good choice. Realize, though that it's not a trivial undertaking. There aren't any C++ language bindings for WebDriver, as far as I know, but as long as you have a JSON parsing library (json-cpp is pretty good), and an HTTP client library, you can write your own language bindings in pretty short order.

like image 163
undetected Selenium Avatar answered Oct 21 '22 10:10

undetected Selenium