简体   繁体   English

使用GeckoDriver和Python的Selenium firefox webdriver未知错误

[英]Selenium firefox webdriver unknown error using GeckoDriver and Python

I've created many test cases using: 我使用以下方法创建了许多测试用例:

  • Firefox v55 Firefox v55
  • Python 2.7.3 Python 2.7.3
  • GeckoDriver v0.19.0 GeckoDriver v0.19.0

This scenario is beeing used by around 50 test cases 该场景被约50个测试用例使用

try:
    caps = DesiredCapabilities.FIREFOX
    caps["wires"] = True
    driver = webdriver.Firefox(capabilities=caps)
    driver.maximize_window()

    self.log("Selenium driver created for %s" % browser)
    return self.STATUS.PASS, driver

except Exception, e:
    self.log("Error when creating selenium driver")
    self.log(traceback.format_exc())
    return self.STATUS.FAIL 

This code simple creates a Firefox web driver, and it is working fine in all the test cases but 1, in one in particular when I execute it in a daily execution i got the following error 这段代码简单地创建了一个Firefox Web驱动程序,并且在所有测试用例中都能正常工作,但是1,特别是当我在日常执行中执行它时,出现以下错误

Traceback (most recent call last):

File "C:\QA Tools\selenium\CreateSeleniumDriver.py", line 26, in run

driver = webdriver.Firefox(capabilities=caps)

File "c:\python27\lib\site-packages\selenium-3.5.0-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 154, in __init__
keep_alive=True)

File "c:\python27\lib\site-packages\selenium-3.5.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)

File "c:\python27\lib\site-packages\selenium-3.5.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)

File "c:\python27\lib\site-packages\selenium-3.5.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 295, in execute
response = self.command_executor.execute(driver_command, params)

File "c:\python27\lib\site-packages\selenium-3.5.0-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 464, in execute
return self._request(command_info[0], url, body=data)

File "c:\python27\lib\site-packages\selenium-3.5.0-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 538, in _request
body = data.decode('utf-8').replace('\x00', '').strip()

File "c:\python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)

AttributeError: 'NoneType' object has no attribute 'utf_8_decode'

Selenium driver created for Firefox
Error when creating selenium driver
Traceback (most recent call last):
File "C:\QA Tools\selenium\CreateSeleniumDriver.py", line 63, in run
return self.STATUS.PASS, driver

UnboundLocalError: local variable 'driver' referenced before assignment

So, this is breaking a part of selenium web driver, but i have no idea why! 因此,这破坏了硒Web驱动程序的一部分,但是我不知道为什么!

  • I've tried everything to make it work 我已经尽了一切努力使其工作
  • This works in all other scenarios I'm using it 这在我正在使用的所有其他情况下都有效
  • This only happens on Firefox 这仅在Firefox上发生
  • This works if it is executed manualy, but not working when executed on a daily execution with all others test cases (any related to this kind of execution was checked and not problem found) 如果手动执行此操作有效,但在与其他所有测试用例一起日常执行时不起作用(已检查与这种执行相关的任何内容,未发现问题)

Any ideas what could be going on wrong? 任何想法可能出了什么问题吗?

This looks like you're running into this bug filed on the official Python bug tracker: https://bugs.python.org/issue14847 看起来您好像遇到了此错误,该错误已归档在官方Python Bug跟踪器上: https : //bugs.python.org/issue14847

The comments there suggest that the issue might be related to one of two things: 那里的评论表明该问题可能与两件事之一有关:

  1. Installing packages with distribute , due to a bug known to exist at least in distribute 0.6.26 . 由于已知至少存在distribute 0.6.26的错误,因此使用distribute安装软件包。 If your "daily execution" relies on installing with this bugged version of distribute , that may explain your issue. 如果你的“每天执行”依赖于与此bug的版本的安装distribute ,这可能说明你的问题。 Do you know if you do this? 你知道你是否这样做吗? And can you update the version of distribute used in your environment, or perhaps use virtual environments to avoid it? 您是否可以更新您的环境中使用的distribute版本,或者可以使用虚拟环境来避免这种情况?

  2. Some other way of manipulating sys.modules such that codecs is not found and gives None instead. 操纵sys.modules其他方法,使得找不到codecs ,而是提供None Does your code do anything like this in some kind of fancy test setup? 您的代码在某种精美的测试设置中是否会执行类似的操作?

Judging by the trace, you've modified your code for brevity, but in a way that might not completely capture the original logic. 从跟踪的角度来看,为了简洁起见,您已经修改了代码,但是可能无法完全捕获原始逻辑。 The UnboundLocalError suggests that your assignment of driver was skipped, and you didn't return right away: UnboundLocalError建议跳过您的driver分配,并且您没有立即返回:

try:
    caps = DesiredCapabilities.FIREFOX
    caps["wires"] = True
    # This line raises an AttributeError deep inside a standard python lib:
    driver = webdriver.Firefox(capabilities=caps)
    driver.maximize_window()

    self.log("Selenium driver created for %s" % browser)

except Exception, e:
    # The driver variable was never actually created or assigned due to the
    # AttributeError above.
    self.log("Error when creating selenium driver")
    self.log(traceback.format_exc())

# Some omitted code...

# The driver variable does not exist past the try if the exception happened
# before assignment to driver. So this raises the UnboundLocalError:
return self.STATUS.PASS, driver

You can fix UnboundLocalError pretty easily by doing the return inside the except, or pre-assigning driver to None or something, but that won't fix the underlying issue creating the driver. 您可以通过在except内进行返回,或将driver预先分配为None或其他方式,很容易地修复UnboundLocalError ,但这不能解决创建驱动程序的根本问题。 That sounds like an issue with your execution environment. 这听起来像您的执行环境有问题。 Maybe something in your run infrastructure is doing something fancy (what are you using as your test runner?) or perhaps there's something corrupt in the Python environment of your daily execution runner. 也许您的运行基础架构中的某件事正在做一些花哨的事情(您用作测试运行者吗?),或者您的日常执行运行者的Python环境中存在某些损坏。 Depending on what the issue is, you might be able to solve the problem by defining a specific virtualenv for all test execution, so you can be sure it runs the same manually as it does in the automatic daily execution. 根据问题所在,您可以通过为所有测试执行定义特定的virtualenv来解决问题,因此可以确保它手动运行与每天自动执行相同。

暂无
暂无

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

相关问题 在Firefox GeckoDriver中使用Python Selenium WebDriver时出现无效的安全证书错误 - Invalid Security Cert error when using Python Selenium WebDriver with Firefox GeckoDriver Python Selenium 和 FireFox \\ geckodriver - Python Selenium and FireFox \ geckodriver 通过geckodriver的Selenium Firefox Webdriver导致错误:“ geckodriver”可执行文件必须位于PATH中 - Selenium Firefox webdriver via geckodriver results in error: 'geckodriver' executable needs to be in PATH InvalidArgumentException:消息:二进制不是使用 GeckoDriver Firefox Selenium 和 Python 的 Firefox 可执行文件错误 - InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python 使用Selenium Webdriver和FireFox时出错 - Error using Selenium Webdriver and FireFox Python 3:Selenium和geckodriver错误? - Python 3: Selenium & geckodriver error? OSError:[Errno 8] Exec格式错误:'geckodriver'试图在python中使用selenium打开firefox - OSError: [Errno 8] Exec format error: 'geckodriver' when trying to open firefox using selenium in python 类型错误:get() 缺少 1 个必需的位置参数:使用 GeckoDriver 和 Firefox 到 Selenium 和 Python 时出现“url”错误 - TypeError: get() missing 1 required positional argument: 'url' error using GeckoDriver and Firefox through Selenium and Python OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows - OSError: [WinError 193] %1 is not a valid Win32 application error using GeckoDriver and Firefox through Selenium and Python on Windows 504 网关超时错误使用 Firefox 68.9.0esr 在无头模式下使用 GeckoDriver Selenium 和 Python - 504 Gateway Time-out error using Firefox 68.9.0esr in headless mode with GeckoDriver Selenium and Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM