環境:
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.可以使用指令行增加這個系統資料庫值。
參考網站:
https://github.com/SeleniumHQ/selenium/issues/5966
https://bugs.chromium.org/p/chromium/issues/detail?id=848232
http://chromedriver.chromium.org/getting-started