I add the below dependency and code for Opening Chrome,but browser is not opening.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.50.0</version>
</dependency>
My code :-
package example;
import org.openqa.selenium.WebDriver;`
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class DepChrome {
@Test
public void testBrowser() {
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
}
}
Add below dependies as below:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.0.0</version>
<!-- <scope>test</scope> -->
</dependency>
Source: copy new dependencies version from below URL:
https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
use below code :
WebDriver driver = null;
WebDriverManager.chromedriver().browserVersion("77.0.3865.40").setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("enable-automation");
options.addArguments("--no-sandbox");
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
Basically below line of code did the trick, below code to download a specific version
WebDriverManager.chromedriver().browserVersion("77.0.3865.40").setup();
Required version you can get from below URL:
https://chromedriver.storage.googleapis.com/index.html
you can also use below code instead of above, if you are looking for latest dependencies present on above chromedriver URL
WebDriverManager.chromedriver().setup();
OR (Old Way)
You need to give path of chrome binary as below:
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
Download the binary of chrome from selenium site as below :- http://chromedriver.storage.googleapis.com/index.html?path=2.21/
Now provide the path of the binary to selenium as :-
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
There is one more thing to take care. if you are using windows then use backward slash \\
and if you are using mac or linux then use forward slash //
for setting up the path.
Hope it will help you :)