Showing posts with label chrome. Show all posts
Showing posts with label chrome. Show all posts

Thursday, July 7, 2016

Sample webdriver scripts to Navigate url

Two methods:

Method 1:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class goTo {

public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
}

}

Method 2:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class goTo {

public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://www.google.com");
}

}

Differences between navigate().to() and get()

driver.get("http://www.google.com");
Webdriver will wait until the page has fully loaded before returning the control to test or script. If there many ajax calls in the current page which webdriver is loading then webdriver may not know when it has loaded completely. If you need to make sure such pages are fully loaded then you can use waits.
Earlier, we covered navigating to a page using the get command (driver.get("http://www.example.com")) As you have seen, webdriver has a number of smaller, task-focused interfaces, and navigation is a useful task. Because loading a page is such a fundamental requirement, the method to do this lives on the main Webdriver interface, but it’s simply a synonym to:
driver.navigate().to("http://www.google.com");


Monday, July 14, 2014

Sample selenium code to launch web browsers(Chrome, InternetExplorer, Firefox) using java

Google Chrome:


  1.     Download the chromedriver.exe file based on your browser version from this link     http://chromedriver.storage.googleapis.com/index.html
  2. Once download completed copy the chromedriver.exe file and paste it in windows folder or you can set the environmental variables path to the location of chromedriver.exe(Ex location path like:D:\chromedriver.exe).
  3. Download latest selenium server jar file from this link http://docs.seleniumhq.org/download/ and then add this jar into your project build path.
  4. Below I have pasted my selenium code to launch the browser for your reference 
                     import org.openqa.selenium.WebDriver;
                     import org.openqa.selenium.chrome.ChromeDriver;

                    public class Test {
               public static void main(String[] args) {
             // TODO Auto-generated method stub
             WebDriver driver = new ChromeDriver(); // launch the browser
            driver.get("http://www.google.com"); // navigate to url

            }

                 }

InternetExplorer:


  1.     Download the IEdriverserver.exe file based on your OS version(32bit/64bit) from this link     http://docs.seleniumhq.org/download/
  2. Once download completed copy the IEdriverserver.exe file and paste it in windows folder or you can set the environmental variables path to the location of IEdriverserver.exe(Ex location path like:D:\IEdriverserver.exe).
  3. Download latest selenium server jar file from this link http://docs.seleniumhq.org/download/ and then add this jar into your project build path.
  4. Below I have pasted my selenium code to launch the browser for your reference 
                     import org.openqa.selenium.WebDriver;
                     import org.openqa.selenium.ie.InternetExplorerDriver;

                    public class Test {
               public static void main(String[] args) {
             // TODO Auto-generated method stub
             WebDriver driver = new InternetExplorerDriver(); // launch the browser
            driver.get("http://www.google.com"); // navigate to url

            }

                 }
Firefox:
  1. Download latest selenium server jar file from this link http://docs.seleniumhq.org/download/ and then add this jar into your project build path.Note:New selenium jar supports all version of firefox browsers so better use latest selenium server jar.
  2. Below I have pasted my selenium code to launch the browser for your reference 
                     import org.openqa.selenium.WebDriver;
                     import org.openqa.selenium.firefox.FirefoxDriver;

                    public class Test {
               public static void main(String[] args) {
             // TODO Auto-generated method stub
             WebDriver driver = new FirefoxDriver();// launch the browser
            driver.get("http://www.google.com"); // navigate to url

            }

                 }