【问题标题】:Selenium not starting portable chrome but local installationSelenium 没有启动便携式 chrome 而是本地安装
【发布时间】:2015-09-28 07:44:03
【问题描述】:

我的 Selenium Web 驱动程序有问题。我想要做的是启动一个“便携式”chrome 而不是我的本地安装,因为它有不同的设置。

问题在于,便携式 Chrome(来自 PortableApps)似乎只有在使用 GoogleChromePortable.exe 时才能启动。如果我直接使用 Chrome 二进制文件,它将开始我的本地安装。 使用 Selenium,似乎无论我传递给它的 Chrome 路径(GoogleChromePortable.exe 还是二进制路径),它都会启动我的本地安装。

这是我的代码:

String chromePath = "M:/my/path";
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
capabilities.setCapability("chrome.binary", chromePath);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

任何想法如何能够启动我的便携式 chrome? 谢谢

【问题讨论】:

    标签: google-chrome selenium


    【解决方案1】:

    对于遇到此问题的其他人,这是我设法启动便携式 Chrome 的方法:

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setBinary(binaryPath);
    driver = new ChromeDriver(chromeOptions);
    

    【讨论】:

      【解决方案2】:

      我在 Windows 10 上使用 Python 3.7,并从 PortableApps.com 获得了 Chrome Portable。

      @mario.schlipf 和 @SeJaPy 的

      cmets 很有帮助,但我注意到在较新的 Webdriver 版本中,setbinary 方法已被 binary_location

      这就是它对我的实际工作方式:

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      
      chromedriverpath='M:/my/chromedriver.exe'
      chromePath = 'M:/my/App/Chrome-bin/chrome.exe'    #  <==  IMPORTANT! See note below.
      
      chromeoptions = Options()
      chromeoptions.add_argument('--incognito')
      chromeoptions.binary_location = chromePath   
      
      browser = webdriver.Chrome(executable_path=chromedriverpath, options=chromeoptions)
      

      注意:

      chromePath 变量必须指向可移植环境中的 Chrome 可执行文件。

      在从 PortableApps.com 获得的软件包中,您有两个可执行文件:安装(实际上是解包)目录中的 GoogleChromePortable.exechrome.exe em>[installdirectory]/App/Chrome-bin,第一个“只是”一个启动器,它为便携式应用程序提供一致的环境。

      据我观察,chromedriver 需要直接与“真正的”Chrome 可执行文件交互,否则脚本将启动浏览器(通过启动器)但最终会崩溃并显示错误消息:

      unknown error: DevTools Active Port file doesn't exist

      因此不会返回任何浏览器会话。

      这对很多人来说似乎很明显......但对我来说不是,所以我决定写下这个注释,以便让不太聪明的人(包括我自己)更清楚:)。

      【讨论】:

      【解决方案3】:
        String chromePath = "M:/my/googlechromeporatble.exe path"; 
        String chromedriverpath="M:/my/chromedriver.exe path";
        ChromeOptions options = new ChromeOptions();
        options.setBinary(chromepath);
        System.setProperty("webdriver.chrome.driver",chromedriverpath);              
        driver = new ChromeDriver(options);
      

      这将调用便携式 chrome 而不是本地安装。 先设置谷歌浏览器可移植路径,然后调用chromeriver.exe

      【讨论】:

        【解决方案4】:

        根据您在 ChromePortable 中的设置,也许您可​​以默认 ChromeDriver 为 Capabilities & ChromeOptions

        我特别想custom profile。如果你能以某种方式从你的 ChromePortable 中获取它并使用默认的 ChromeDriver 加载它?

        编辑:也许this 可以提供帮助

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-06-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-07-04
          • 2015-02-23
          相关资源
          最近更新 更多