Web Driver Basics -1



WebDriver Basics-1

The main new feature in Selenium 2.0 or higher versions is the integration of the WebDriver

Selenium ver 2.x series has WebDriver and RC also for backward compatibility.

WebDriver is developed to better support for dynamic web pages where the elements on a page change without the page being reloaded.

WebDriver’s goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems.

WebDriver makes direct calls to the browser using each browser’s native support for automation.

WebDriver provides
          FirefoxDriver
          InternetExplorerDriver
          ChromeDriver
Classes , we can create object for these classes and directly interact with browser

Ex:  The below example type selenium in google and click Search

            import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

public class google
{
            public static void main(String args[]) throws Exception
            {
                  FirefoxDriver fd=new FirefoxDriver();
                  ///open the given url
                  fd.get("http://www.google.com");
                  Thread.sleep(5000);
                  ////findelement q and type selenium
                  fd.findElement(By.name("q")).sendKeys("selenium");
                  ////findelement  btnG and click
                  fd.findElement(By.name("btnG")).click();
                  Thread.sleep(3000);       
            }
}


Ex:  The below example login into yahoo

            import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

public class yahoo
{
            public static void main(String args[]) throws Exception
            {
                  FirefoxDriver fd=new FirefoxDriver();
                  ///open the given url
                  fd.get("http://www.yahoomail.com");
                  Thread.sleep(5000);
                  ////findelement login and type yahooid
                  fd.findElement(By.name("login")).sendKeys("xxx);
                  ////findelement passwd and type password
                  fd.findElement(By.name("passwd")).sendKeys("xxx);
                  ////findelement signin and click
                  fd.findElement(By.name(".save")).click();
            }
}

Comments