2012-07-10 122 views
0

我想在Windows 7上使用python中的selenium webdriver打開chrome瀏覽器,但它掛起。下面是我使用的代碼:硒在python中無法在win7上打開chrome瀏覽器?

`

from selenium import webdriver 
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.common.proxy import * 
import time 
from pprint import pprint 

chromeOps = webdriver.ChromeOptions() 
print "after chrome opts", chromeOps 
print dir(chromeOps) 
pprint(chromeOps) 
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe" 

print "after binary loc" 
browser = webdriver.Chrome("C:\\Python27\\chromedriver.exe", chrome_options=chromeOps) 
print "after browser", browser 
print dir(browser) 
browser.get("http://www.google.com") 

`

你能幫助我嗎?謝謝!

+0

我看到你有一些調試代碼在那裏。它掛着什麼電話?你是否收到任何錯誤輸出? – 2012-07-10 13:38:33

+0

這裏沒有任何錯誤。這裏有兩條最後一行的輸出前掛: 二進制loc後 服務網址http:// localhost:64960 – 2012-07-10 13:54:29

+0

有時達到最後,但它不打開瀏覽器。 – 2012-07-10 13:57:39

回答

0

刪除:

chromeOps = webdriver.ChromeOptions() 
print "after chrome opts", chromeOps 
print dir(chromeOps) 
pprint(chromeOps) 
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe" 

print "after binary loc" 

現在看到發生了什麼。當我實例化chrome時,我只是設置了chromedriver的路徑,它對我來說工作正常,也可能是在Python27中運行chrome驅動程序的燙髮問題,請嘗試將其移動到其他地方

+0

謝謝你的迴應。我嘗試了這些包括和'browser = webdriver.Chrome(「C:\\ chromedriver.exe」)',但沒有任何反應。在任務管理器中,我可以看到它打開了chromedriver,但沒有chrome進程。你在Win7上運行它嗎? – 2012-07-11 08:14:26

+0

另外我必須指定我在64位平臺上有win7。這是否會成爲chromedriver打開Chrome瀏覽器的問題? – 2012-07-11 08:33:35

0

我做了一些更改,拿出ChromeOpts,因爲我的電腦上沒有這個文件,而且它對我很有用。確保你將chromedriver添加到PATH,你應該沒問題。

from selenium import webdriver 
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.common.proxy import * 
import time 
from pprint import pprint 
import os 



chromedriver = "C:\Users\USER\AppData\Local\Google\Chrome\Application\chromedriver.exe" 
os.environ["webdriver.chrome.driver"] = chromedriver 

print "after binary loc" 
browser = webdriver.Chrome(chromedriver) 
print "after browser", browser 
print dir(browser) 
browser.get("http://www.google.com") 
相關問題