How to setup Selenium webdriver and execute automation script

  • Selenium 2.0 includes selenium web driver compatible version.
  • Download Selenium 2.0 from http://seleniumhq.org/download/
  • Install Java JRE, JDK is not required until you want to create Java programs
  • Check java version- java –version on command prompt, to be sure you have java installed
  • Start selenium through command prompt: java -jar selenium-server-standalone-<version-number>.jar
  • You can also Stop Selenium through browser: http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
  • Write code in PHP i.e. download library (php-webdriver-bindings-0.9.0.zip) from http://code.google.com/p/php-webdriver-bindings/ to execute selenium scripts
  • Save the following code as “myseleniumscript.php” file.
<?php
require_once "phpwebdriver/WebDriver.php";

$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
$element->sendKeys(array("selenium google code" ) );
$element->submit();

$webdriver->close();
?>
  • Make sure you have php and supporting web server like Apache already installed. Download “wamp” to install PHP, Apache
  • Run the file as localhost/myfolder/myseleniumscript.php in browser, this will open up a new firefox window and you can also check the command prompt for execution log
Bookmark and Share
Both comments and pings are currently closed.

Comments are closed.

n