最近在研究 selenium Grid;在测试验证的过程中遇到点问题;

在 selenium 的 Node 节点中指定了浏览器的路径和 webdriver 路径;但是运行测试代码时却启动了默认的 Chrome 浏览器
Node 节点配置文件如下;doreadme.exe 浏览器是一个换皮 chromne 浏览器;

{
  "capabilities":
  [
    {
      "browserName": "firefox",       
      "platform": "WINDOWS",       
      "maxInstances": 5,       
      "seleniumProtocol": "WebDriver",       
      "webdriver.gecko.driver": "D:/drivers/geckodriver.exe",       
      "binary":"C:/Program Files/Mozilla Firefox/firefox.exe"
    },
    {
      "browserName": "chrome",
      "platform": "WINDOWS",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver",
      "webdriver.chrome.driver": "d:/doreadme/chromedriver.exe",
      "binary": "d:/doreadme/doreadme.exe"
    }
  ],
  "maxSession": 5,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://192.168.104.209:4444/grid/register",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

测试代码

#!/usr/bin/env python3
#encoding = utf-8
import time
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# 指定Hub服务器地址、并设定浏览器
driver = webdriver.Remote(
     command_executor='http://192.168.104.209:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.CHROME)

# 访问百度、并执行搜索操作
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium")
driver.find_element_by_id("su").click()
time.sleep(5)
driver.close()

代码运行之后、很悲催的发现 Node 测试机器上的 chrome 浏览器启动了、而不是启动的 d:/doreadme/doreadme.exe 程序

但是我单独用 selenium 是可以配置指定浏览器程序的

path = 'd:/doreadme/chromedriver.exe'
do_options = webdriver.ChromeOptions() 
do_options.binary_location = r'D:/doreadme/doreadme.exe'  #指定路径

搜索引擎翻了很久、selenium 官网文档也没找到解决办法;


↙↙↙阅读原文可查看相关链接,并与作者交流