Wednesday, January 13, 2016

Selenium Chrome Driver Usage

Available constructors for Chrome Driver




A list of all Chrome Driver Capability

https://sites.google.com/a/chromium.org/chromedriver/capabilities

Chrome Driver usage for constructor ChromeDriver(service, options);

Opening a already created Chrome profile to a new Chrome browser instance.
To create a new chrome profile, enter chrome://version/ in chrome navigation bar and checkout the profilePath. Close the browser and rename the default profile path.

Now if you open the Chrome browser the browser will create a new default profile folder Default again
OR
you can use the below method and start an instance of Chrome browser by setting
options.addArgument("user-data-directory=C:/xx/xx/profile_name")

          // USE OF CHROME Driver constructor ChromeDriver(service, options)
 public static void ChromeLocalDriver02(WebDriver driver) {
  System.setProperty("webdriver.chrome.driver", "C:\\Java_Source_Code\\chromedriver_win32\\chromedriver.exe");
  // setting up the service
  ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
  ChromeDriverService service = builder.withLogFile(new File("C:\\Test\\ie_log\\chrome1.log")).build();
  // chrome options
  ChromeOptions options = new ChromeOptions();
  // Opening Chrome browser with current default profile
  options.addArguments("user-data-dir=C:\\Users\\sudas\\AppData\\Local\\Google\\Chrome\\User Data\\sudas");
  // this is to start Chrome windows as maximized
  options.addArguments("start-maximized");
  driver = new ChromeDriver(service, options);
 } 
      }  


To find out which profile the browser is currently using enter chrome://version/ in Chrome's address bar and checkout the "ProfilePath"

Chrome Driver usage for constructor ChromeDriver(service, capabilities);


      // USE OF CHROME Driver CAPABILITY through DesiredCapabilities  
      // Used constructor ChromeDriver(service, capabilities)  
      public static void ChromeLocalDriver01(WebDriver driver) {  
           System.setProperty("webdriver.chrome.driver", "C:\\Java_Source_Code\\chromedriver_win32\\chromedriver.exe");  
           // "ChromeDriverService" similar to InternetExplorerDriverService  
           ChromeDriverService.Builder builder = new ChromeDriverService.Builder();  
           ChromeDriverService service = builder.withLogFile(new File("C:\\Test\\ie_log\\chrome1.log")).build();  
           DesiredCapabilities capabilities = new DesiredCapabilities();  
           // capabilities.setCapability(ChromeDriverService.CHROME_DRIVER_VERBOSE_LOG_PROPERTY,  
           // true);  
           capabilities.setCapability(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, true);  
           driver = new ChromeDriver(service, capabilities);  
      }  

Chrome Driver usage for constructor ChromeDriver(capabilities);

      public static void ChromeLocalDriver03(WebDriver driver) {  
           System.setProperty("webdriver.chrome.driver", "C:\\Java_Source_Code\\chromedriver_win32\\chromedriver.exe");  
           ChromeOptions options = new ChromeOptions();  
           options.addExtensions(new File("C:\\DRIVE\\My Documents\\Downloads\\AdBlock_v2.46.crx"));  
           DesiredCapabilities capabilities = new DesiredCapabilities();  
           capabilities.setCapability(ChromeOptions.CAPABILITY, options);  
           driver = new ChromeDriver(capabilities);  
      }  

1 comment: