Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

selenium - What is default location of ChromeDriver and for installing Chrome on Windows

I need to install chromedriver on Windows OS. In the article below they specify:

https://sites.google.com/a/chromium.org/chromedriver/getting-started

"...ChromeDriver expects you to have Chrome installed in the default location for your platform..."

But I'm not sure what is the default location ?

On Mac OS it's /usr/local/bin.

With this I don't have to specify path explicitly or setup system path either.

How to achieve the same on Windows OS?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

These are two interrelated important questions as follows :

  • Default location of ChromeDriver
  • Default location of Chromium/Google Chrome

ChromeDriver

You can download the recently released ChromeDriver from ChromeDriver - WebDriver for Chrome page and place it any where within your system. When you initialize the ChromeDriver you need to pass the absolute path of the ChromeDriver binary.

Additionally, you can also help WebDriver to locate the downloaded ChromeDriver executable through the following steps :

  • Include the ChromeDriver location in your system PATH environment variable.
  • (Java) Specify the location of ChromeDriver through the webdriver.chrome.driver system property
  • (Python) Specify the location of ChromeDriver when instantiating webdriver.Chrome()

Chromium/Google Chrome

The most important fact is you need to ensure that Chromium/Google Chrome is installed in a recognized location as per the ChromeDriver - Requirements as the server expects you to have Chromium/Google Chrome installed in the default location for each system as per the snapshot:

ChromeDriver - Requirements

Note : For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. You can also override the Chrome binary location following Using a Chrome executable in a non-standard location .

Sample Code Block

  • Java :

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class A_Chrome 
    {
        public static void main(String[] args) 
        {
            // Optional : if not specified WebDriver will search your system PATH environment variable for locating the chromedriver
            System.setProperty("webdriver.chrome.driver", "C:\path\to\chromedriver.exe");
            WebDriver driver =  new ChromeDriver();
            driver.get("https://www.google.co.in");
            System.out.println(driver.getTitle());
            driver.quit();
        }
    }
    
  • Python :

    from selenium import webdriver
    
    # Optional argument : if not specified WebDriver will search your system PATH environment variable for locating the chromedriver
    driver = webdriver.Chrome(executable_path=r'C:pathochromedriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...