【问题标题】:Run Selenium with chromedriver in Jenkins在 Jenkins 中使用 chromedriver 运行 Selenium
【发布时间】:2017-11-17 07:31:15
【问题描述】:

我正在尝试在 Jenkins (CI) 中使用 Selenium 和 chromedriver 运行基本脚本。

基本上我完成了运行脚本应该采取的所有步骤,但我仍然收到如下错误:

WebDriverException:消息:服务 chromedriver 意外退出。状态码是:127

“chrome”可执行文件需要在 PATH 中。

我已经在 J​​enkins 中安装了 chrome 驱动程序插件(基本上我已经安装了任何可以相关的插件)但我仍然无法运行脚本。

脚本是:

import os
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

def chat():

# setting Chrome headless webdriver
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
chrome_driver = os.getcwd() + "/chromedriver"
driver = webdriver.Chrome(chrome_options=chrome_options, 
executable_path=chrome_driver)


# set url's
website_url = "<some url>"

# verify the website and BO are live
web = requests.get(website_url)
if web.status_code != 200:
    raise Exception("Error in URL's")
else:
    driver.get(website_url)
    driver.find_element_by_id("some_id").click()
    driver.quit()

代码只是为了展示我如何调用 chromedriver

我做错了什么?我是否缺少运行这种脚本的集合?

【问题讨论】:

  • 确保您的executable_path 正确,否则将.exe 文件保留在该文件所在的同一路径中
  • Chrome 驱动程序 != chrome 可执行文件。在 PATH 变量中编辑您正在运行测试的环境,以附加 chrome 二进制文件的位置。如果 Jenkins 在您自己以外的系统用户上运行,请确保该用户对 chrome 位置具有读取/执行权限。可能值得一提的是您正在运行 Linux,这将使您免于获得与 Windows 相关的答案。

标签: python selenium jenkins selenium-chromedriver


【解决方案1】:

错误 'chrome' executable needs to be in PATH 说明了一切。

可能的原因是:

  • Google Chrome 未安装在默认位置。
  • 实际Chrome Browser Binary 路径与Environmental Variables 中设置的不匹配

解决办法:

  • 确保实际Chrome Browser Binary 路径与Environmental Variables 中的设置匹配
  • 通过Revo Uninstaller彻底卸载Chrome Browser,并确保与Chrome相关的Registry Entries被删除。
  • 安装Chrome Browser
  • 执行您的Test

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 2013-07-26
    • 2014-10-07
    • 2017-04-24
    • 2014-11-22
    • 2015-09-12
    相关资源
    最近更新 更多