【发布时间】:2024-07-14 08:10:01
【问题描述】:
我曾经有一个 Python 中的 selenium 脚本代码,用于一个运行良好的 firefox 网站。一段时间后,我更新了 Firefox (48) 和 selenium 2.9.1.1,python 是 3.5.0
代码,
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re, os
class Jqueryx(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://127.0.0.1:8080/"
self.verificationErrors = []
self.accept_next_alert = True
self.path_upload_quest = r'C:\\Users\jl\Documents\DONNEES\DONNEES_LIMONDE'
self.path_upload_ref = r'C:\\Users\jl\Documents\DONNEES\DONNEES_LIMONDE\ref'
def test_jqueryx(self):
driver = self.driver
driver.get(self.base_url + "/lim/home.php")
如果我现在运行脚本,我会收到以下消息:
os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException:消息:'geckodriver'>可执行文件需要在 PATH 中。
所以我下载了这个 geckodriver 东西并尝试将它添加到 python 中,但还没有任何效果,
我尝试在脚本中添加这个;
os.environ["PATH"] += r'C:\Users\jl\geckodriver'
没有成功或在 site-package 文件夹中添加 .pth 文件但也没有更改...
我该怎么做才能让这个脚本回到正轨?
谢谢
【问题讨论】:
-
这可能是您修改
PATH的方式的问题。您需要在附加 geckodriver 路径之前包含路径分隔符:os.environ["PATH"] += os.pathsep + r'C:\Users\jl\geckodriver' -
在 Selenium 和 47 之后(包括)之后的任何 Firefox 版本之间都存在问题。最好降级到 46 直到问题得到解决。
-
thx 没有运气改变包含路径的方式,但它看起来肯定是问题的根源。无论如何我都必须升级 firefox,所以我更期待这个问题以及如何解决修复它。
标签: python selenium firefox path geckodriver