繁体   English   中英

在Jenkins中使用chromedriver运行Selenium

[英]Run Selenium with chromedriver in Jenkins

我正在尝试在Jenkins(CI)中使用带有Selenium和chromedriver的基本脚本。

基本上,我已经执行了运行脚本应采取的所有步骤,但仍然出现如下错误:

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

要么

“ chrome”可执行文件必须位于PATH中。

我已经在Jenkins中安装了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

我究竟做错了什么? 我是否缺少一套可以运行这种脚本的工具?

一切都'chrome' executable needs to be in PATH错误的'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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM