Run geckodriver before launching the browser


  •   Inorder to launch empty firefox browser,just create a object to browser class,it automatically launches a browser,bcoz constructor has the code to launch empty browser.
  • get() is used to navigate to any web application URL,but URL should start with "http:" or "https:"

Note: Webdriver internally uses http or https protocol for browser communication.

Example as below:

import org.openqa.selenium.firefox.firefoxDriver;

public class SampleFirstTest {
             System.setProperty("webDriver.gecko.Driver",c://....path u should give");
             FirefoxDriver driver=new FirefoxDriver();
             driver.get("https://facebook.com");
   }


Webdriver basic Browser operation:
 
   get()
   navigate().to()
   navigate().refresh();
   navigate().back()
   navigate().forward()
   findElement()
   findElements()
   getTitle()
   getCurrentUrl()
   getPageSource()
   getWindowHandles()
   quit()
   close()
   manage().window().maximize()
   manage().window().setsize()
   manage().deleteAllCookies()

findElement(locators):
  1.  findElement method is used to identify the element in GUI
  2. Technically findElement() is used to navigate entire html document and identify the object by taking locator as a refernce.
  3. findElement method throws "no such element excetion" if object is not available in "UI"
  4. findElement method always return webElement reference if object is available
  5. findElement method can identify the object based on 8 locators

8 Locators are below :
  1.        id()
  2.        name()
  3.        xpath()
  4.        cssselector()
  5.        linkText()
  6.       partialLinkText()
  7.       className()
  8.       tagName()
Example as below for Find WebElement(EditBox)in GUI based on locator:
 
   WebElement wb= driver.findElement(By.id("Email"));
   //Perform action on webElement
   wb.sendKeys("test@gmail.com"); 

 All locators are static methods implemented inside the By class.

Example Program:

   Class GmailLoginTest
   {
     public static void main(String[]args)throws InteruptedException {

         System.setProperty("webDriver.gecko.Driver",c://....path u should give");
         FirefoxDriver driver = new FirefoxDriver();
                 driver.get("http://www.gmail.com");

               //Login
        driver.findElement(By.id("Email")).sendKeys("give ur gmail");
       driver.findElement(By.id("next")).click();
       Thread.sleep(3000);
       driver.findElement(By.name("password")).sendKeys("give password");
       driver.findElement(By.id("signin")).click();
       Thread.sleep(1000);

          //logout  
        driver.findElement(By.xpath("//a[@class='take it out from inspectelement']")).click();
       Thread.sleep();
       driver.quit();

               }
}


Comments

Post a Comment

Popular posts from this blog

Theme display in javascript

How to know which liferay version we are using

Viewing the SQL Query in liferay : debugging the SQL Query in Hibernate