简体   繁体   中英

[Python][Selenium]Unable to use webdriver with Chrome

I'm a beginner in Python and Selenium, and I dont know what is the error in my code or environment...

# encoding: utf-8
import time
from selenium import webdriver
from bs4 import BeautifulSoup

driver = webdriver.Chrome(executable_path=r'C:/Python27/Scripts/chromedriver') 
time.sleep(3)
driver.get('https://www.google.com.tw/')   
for i in range(10):  
    driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')  
    time.sleep(1)  
    print ("Scrolling...")
driver.close()  

And here is error messages...

C:\\Python27\\python.exe D:/PythonPratice/test.py Traceback (most recent call last): File "D:/PythonPratice/test.py", line 9, in driver.get(' https://www.google.com.tw/ ') File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 250, in get self.execute(Command.GET, {'url': url}) File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 238, in execute self.error_handler.check_response(response) File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py", line 193, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"2172.1","isDefault":true},"id":1,"name":"","origin":"://"} (Session info: chrome=56.0.2924.87) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)

Process finished with exit code 1

Much thanks!

您应该提供chromedriver.exe完整路径,请参见以下内容:

driver = webdriver.Chrome(executable_path=r'C:/Python27/Scripts/chromedriver.exe') 

尝试下载最新版本的chromedriver并将其放到C:/Python27/Scripts/而不是过时的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM