【原創】Selenium 報 xxxMachineLevelUserCloudPolicyEnrollmentToken 的解決辦法
阿新 • • 發佈:2018-12-09
環境:
OS:Windows 10 17134
Python:3.4.4
Selenium:3.13.0
Browser:68.0.3440.84(正式版本) (64 位)
ChromeDriver:2.41
指令碼內容:
# -*- coding: utf-8 -*-
"""
測試 selenium webdriver
"""
import time
from selenium import webdriver
def test():
driver = webdriver.Chrome()
driver.get('http://www.google.com/xhtml' )
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
if __name__ == '__main__':
test()
現象:
指令碼正常執行,指令碼功能也執行正確,但是命令列輸出有錯誤資訊。
錯誤資訊如下:
[17672:21484:0802/155619.485:ERROR:install_util.cc(603)] Failed to read HKLM\SOFTWARE\Policies\Google\Chrome\MachineLevelUserCloudPolicyEnrollmentToken: 系統找不到指定
的檔案。 (0x2)
網上提供的各種解決方案:
1.升級 selenium 版本到最新 - 已確認,無效;
2.chromium 的 bug 報告說讓升級 chrome 到 68.0.3433.0 及以上,並使用對應版本的 ChromeDriver - 已確認,無效;
3.ChromeDriver 使用說明裡建議「(Python only) include the path to ChromeDriver when instantiating webdriver.Chrome」- 已確認,無效;
4.命令列提權執行「reg add HKLM\SOFTWARE\Policies\Google\Chrome /v MachineLevelUserCloudPolicyEnrollmentToken /t REG_SZ」,新增報錯資訊中提示的登錄檔值 - 已確認,有效。
結論:
1.可以手動在 regedit 中增加這個登錄檔值;
2.可以通過 .reg 檔案增加這個登錄檔值;
3.可以使用命令列增加這個登錄檔值。
本文原創釋出於公眾號「sylan215」,十年測試老兵的原創乾貨,關注我,漲姿勢!