問題描述
我正在嘗試使用 chromedriver 2.10 在 CentOS 機器上的 Chrome 瀏覽器版本 35.0.1916.114 上運行測試
/home/varunm/EC_WTF_0.4.10/EC_WTF0.4.10_Project/wtframework/wtf/drivers/chromedriver
/home/varunm/EC_WTF_0.4.10/EC_WTF0.4.10_Project/wtframework/wtf/drivers/chromedriver
實際上我修復了路徑問題,因為如果問題與路徑有關,則錯誤消息會有所不同
Actually I fixed the path issue, because the error message was different if the issue was with path
def start(self):
"""
Starts the ChromeDriver Service.
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
env = self.env or os.environ
try:
self.process = subprocess.Popen([
self.path,
"--port=%d" % self.port] +
self.service_args, env=env, stdout=PIPE, stderr=PIPE)
except:
raise WebDriverException(
"ChromeDriver executable needs to be available in the path.
Please download from http://chromedriver.storage.googleapis.com/index.html
and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
count = 0
while not utils.is_connectable(self.port):
count += 1
time.sleep(1)
if count == 30:
raise WebDriverException("Can not connect to the ChromeDriver")
如果路徑錯誤,我會收到一些其他錯誤,但現在錯誤是在建立連接時
If the path was wrong I will receive some other error, but now the error is while making the connection
推薦答案
適用于 Linux
1.檢查你是否安裝了最新版本的chrome brwoser-> "chromium-browser -version"
2.如果沒有,安裝最新版本的chrome sudo apt-get install chromium-browser"
3. 從以下鏈接獲取適當版本的 chrome 驅動程序 http://chromedriver.storage.googleapis.com/index.html一個>
4.解壓chromedriver.zip
5.將文件移動到/usr/bin/目錄sudo mv chromedriver/usr/bin/
6. 轉到/usr/bin/目錄,你需要運行類似chmod a+x chromedriver"的東西來標記它可執行.
7.終于可以執行代碼了.
For Linux
1. Check you have installed latest version of chrome brwoser-> "chromium-browser -version"
2. If not, install latest version of chrome "sudo apt-get install chromium-browser"
3. get appropriate version of chrome driver from following link http://chromedriver.storage.googleapis.com/index.html
4. Unzip the chromedriver.zip
5. Move the file to /usr/bin/ directory sudo mv chromedriver /usr/bin/
6. Goto /usr/bin/ directory and you would need to run something like "chmod a+x chromedriver" to mark it executable.
7. finally you can execute the code.
import os
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()
這篇關于WebDriverException:消息:“無法連接到 ChromeDriver".utils.is_connectable(self.port) 中的錯誤:的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!