Selenium Commands

1) Launching Browsers in Selenium

Launch “Firefox” browser using selenium

System.setProperty(“webdriver.gecko.driver”, PathToGeckoDriver + “\\geckodriver.exe”);
driver = new FirefoxDriver();

Launch “Chrome” browser using selenium

System.setProperty(“webdriver.chrome.driver”, “E:\\Selenium\\chromedriver.exe”);
driver = new ChromeDriver();

Launch “IE” browser using selenium

System.setProperty(“webdriver.ie.driver”,”E:\\lib\\IEDriverServer.exe”);  
driver=new InternetExplorerDriver();

2) Selenium Navigation Commands Forward, Backward, Refresh

  • driver.navigate().to(“http://www.techlearn.in”);

  • driver.get(“http://www.techlearn.in/mohana”);

  • driver.navigate().back();

  • driver.navigate().forward();

  • driver.navigate().refresh();

3) List of “Locators / Elements” in selenium

  • id
    driver.findElement(By.id(“gbqfq”)).sendKeys(“TechLearn”);
  • name
    driver.findElement(By.name(“q”)).sendKeys(“TechLearn”);
  • className
    driver.findElements(By.className(“techlearn”));
  • cssSelector
    driver.findElement(By.cssSelector(“input.form-submit“)).click();
  • linkText
    driver.findElement(By.linkText(“Sign-in”)).click();
  • partialLinkText
    driver.findElement(By.partialLinkText(“selenium”));
  • tagName
    driver.findElement(By.tagName(“iframe”));
  • xpath
    • RelativeXpath
      driver.findElement(By.xpath(“(//input[@id=’gender’])[2]”)).click();
    • AbsoluteXpath
      driver.findElement(By.xpath(“/html/body/div[3]/div/header/div/nav/div/div/ul/li[1]/a”)).click();

 

Leave a Reply