How to Run Webdriver in chrome browser?


how to open chrome in selenium



How to Run Webdriver in chrome browser?


To run the Chrome browser in selenium we need to download the Chrome driver separately from the below link
https://sites.google.com/a/chromium.org/chromedriver/.  It will provide you with the latest driver and it’s nothing but an ‘.exe file’.  You just need to download it and unzip the file in a proper location.

I can assume that you already know how to install selenium and setup a selenium project. If you do not know how to then you can refer to my previous post selenium installation process for the purpose of setting up a selenium project.

The next thing you need to do is to set the property for Chrome driver and specify its location via the property ‘webdriver.chrome.driver’ as stated below.


System.setProperty("webdriver.chrome.driver", "pathofchromedriver");


For the next part what you need to do is to provide the path of the Chrome driver. In my case, my Chrome driver is located in ‘D:/workspace/TestProject/src/chromedriver.exe’ . Here,yYou need to provide your Chrome driver path at "pathofchromedriver"; and after that, you need to initialize the chormeDriver


WebDriver  driver = new ChromeDriver();


Open the browser using the ‘get’ method

driver.get(https://www.google.com");

Let’s try to open a Chrome browser using selenium webdriver.
 package com.test;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 public class SeleniumMethod {  
  static WebDriver driver;  
  public static void main(String argc[]){  
  openURL();  
  }  
  public static void openURL(){  
  System.setProperty("webdriver.chrome.driver", "D:/workspace/TestProject/src/chromedriver.exe");   
  driver = new ChromeDriver() ;  
  driver.get("https://www.google.com");  
  }  
 }  

Share this

Related Posts

Previous
Next Post »

1 comments:

comments