webdriver 问题小记

原文写于 Cmd Markdown
原文链接:https://www.zybuluo.com/CYTand/note/1208879


在尝试《Jenkins 创建构建任务》这个项目时遇到一些问题,本文用于记录解决方法(可以说是很小白的方法了)。

问题主要在这一步:C:\Users\wis01>python d:/py_tests.py

输出为:

     [5956:4996:0710/155156.898:ERROR:install_util.cc(589)] Unable to create registry key HKLM\SOFTWARE\Policies\Google\Chro
    e for reading result=2

    DevTools listening on ws://127.0.0.1:12075/devtools/browser/9ea3a1c2-613a-4752-a3f8-05f619563ff7
    E[10772:6808:0710/155209.983:ERROR:install_util.cc(589)] Unable to create registry key HKLM\SOFTWARE\Policies\Google\Ch
    ome for reading result=2

    DevTools listening on ws://127.0.0.1:12532/devtools/browser/2315ce85-01b3-441c-8a56-d553470e711b
    E
    ======================================================================
    ERROR: test_case (__main__.TestClass)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "d:/py_tests.py", line 16, in test_case
        self.driver.get(self.base_url)
      File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
        self.execute(Command.GET, {'url': url})
      File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
        self.error_handler.check_response(response)
      File "D:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: unknown error: cannot determine loading status
    from unknown error: missing or invalid 'entry.level'
      (Session info: chrome=67.0.3396.99)
      (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x8
    _64)


    ======================================================================
    ERROR: test_case2 (__main__.TestClass)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "d:/py_tests.py", line 22, in test_case2
        self.driver.get(self.base_url)
      File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
        self.execute(Command.GET, {'url': url})
      File "D:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
        self.error_handler.check_response(response)
      File "D:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: unknown error: cannot determine loading status
    from unknown error: missing or invalid 'entry.level'
      (Session info: chrome=67.0.3396.99)
      (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x8
    _64)


    ----------------------------------------------------------------------
    Ran 2 tests in 25.587s

    FAILED (errors=2)

这里有两种错误:

1、注册表导致

[5956:4996:0710/155156.898:ERROR:install_util.cc(589)] Unable to create registry key HKLM\SOFTWARE\Policies\Google\Chrome for reading result=2

找不到注册信息。

解决方法:

1)打开注册表编辑器

a) 快捷键win+R
b) 输入:regedit
c) 打开regedit.exe

2)找到并按顺序展开以下项目:

-HKEY_LOCAL_MACHINE
    -SOFTWARE
        -Policies

3)在Policies下创建Chrome项:

a) 选中Policies
b) 点击右键
c) 新建 - 项(k)
d) 将该项命名为:Google

4)在Google下创建Chrome项:

a) 选中Google
b) 点击右键
c) 新建 - 项(k)
d) 将该项命名为:Chrome

5)在Chrome下新建MachineLevelUserCloudPolicyEnrollmentToken字串:

a) 选中Chrome
b) 点击右键
c) 新建 - 字符串值(s)
d) 将该字符串命名为:MachineLevelUserCloudPolicyEnrollmentToken

6)若原本已有Google、Chrome项,则直接在下面添加第五步中的字符串值即可。

2、webdriver导致

    WebDriverException: Message: unknown error: cannot determine loading status
    from unknown error: missing or invalid 'entry.level'
      (Session info: chrome=67.0.3396.99)
      (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x8
    _64)

webdriver与Chrome两者版本不匹配(一般来说,两者均保持最新即可)。

解决方法:

1)更新Chrome

2)更新webdriver

参考以下链接提供的webdriver下载地址:
http://www.testclass.net/selenium_python/selenium3-browser-driver/

3)一定要替换原来的webdriver,若忘记了原来的位置,可以到环境变量配置中看一下


以上。

转载于:https://www.cnblogs.com/CYTyeah/p/9358025.html

你可能感兴趣的:(webdriver 问题小记)