ChromeDriver 的默认位置以及在 Windows 上安装 Chrome 的默认位置是什么

2024-04-18

我需要安装chromedriver在 Windows 操作系统上。他们在下面的文章中指定:

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

“...ChromeDriver 希望您默认安装 Chrome 您的平台的位置...”

但我不确定默认位置是什么?

On Mac操作系统是/usr/local/bin.

这样我就不必显式指定路径或设置系统路径。

如何在Windows操作系统上实现同样的效果?


这是两个相互关联的重要问题:

  • 默认位置Chrome驱动程序
  • 默认位置铬/谷歌浏览器

Chrome驱动程序

您可以下载最近发布的Chrome驱动程序 from ChromeDriver - 适用于 Chrome 的 WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads页面并将其放置在系统内的任何位置。当你初始化Chrome驱动程序你需要传递的绝对路径Chrome驱动程序二进制。

此外,您还可以帮助网络驱动程序找到下载的Chrome驱动程序可以通过以下步骤执行:

  • 包括Chrome驱动程序在您系统中的位置PATH环境变量。
  • (Java) 指定位置Chrome驱动程序通过webdriver.chrome.driver 系统属性
  • (Python) 指定位置Chrome驱动程序实例化时webdriver.Chrome()

铬/谷歌浏览器

最重要的事实是您需要确保铬/谷歌浏览器按照以下规定安装在可识别的位置ChromeDriver - 要求 https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver#requirements正如服务器期望您拥有的那样铬/谷歌浏览器根据快照安装在每个系统的默认位置:

Note:对于 Linux 系统,Chrome驱动程序期望/usr/bin/google-chrome成为一个symlink到实际的Chrome 二进制文件。您还可以覆盖Chrome 二进制文件位置下列的在非标准位置使用 Chrome 可执行文件 https://sites.google.com/a/chromium.org/chromedriver/capabilities#TOC-Using-a-Chrome-executable-in-a-non-standard-location .

示例代码块

  • 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:\path\to\chromedriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ChromeDriver 的默认位置以及在 Windows 上安装 Chrome 的默认位置是什么 的相关文章

随机推荐