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.
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 chormeDriverWebDriver driver = new ChromeDriver();
Open the browser using the ‘get’ method
driver.get(https://www.google.com");
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");
}
}
1 comments:
commentsAwesome
Reply