慕桂英3389331
2019-08-15 15:24:57
在chrome中運(yùn)行Selenium WebDriver python綁定我在使用Selenium時遇到了問題。對于我的項(xiàng)目,我必須使用Chrome。但是,在使用Selenium啟動它后,我無法連接到該瀏覽器。出于某種原因,Selenium無法單獨(dú)找到Chrome。當(dāng)我嘗試在不包含路徑的情況下啟動Chrome時會發(fā)生這種情況:Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome() # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 58, in start and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path. Please download from http://code.google.com/p/selenium/downloads/list and read up at http://code.google.com/p/selenium/wiki/ChromeDriver'為了解決這個問題,我在啟動Chrome的代碼中包含了Chromium路徑。但是,解釋器無法找到要連接的套接字:Traceback (most recent call last):
File "./obp_pb_get_csv.py", line 73, in <module>
browser = webdriver.Chrome('/usr/bin/chromium') # Get local session of chrome
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
self.service.start()
File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 64, in start raise WebDriverException("Can not connect to the ChromeDriver")selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the ChromeDriver'我也嘗試通過啟動chrome來解決問題:鉻--remote-shell-port = 9222但是,這也不起作用。PS。這是關(guān)于我的系統(tǒng)的一些信息:www-client:chromium 15.0.874.121 dev-lang:python 2.7.2-r3 Selenium 2.11.1 操作系統(tǒng):GNU / Linux Gentoo內(nèi)核3.1.0-gentoo-r1
3 回答

米琪卡哇伊
TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個贊
您需要確保獨(dú)立的ChromeDriver二進(jìn)制文件(與Chrome瀏覽器二進(jìn)制文件不同)位于您的路徑中,或者在webdriver.chrome.driver環(huán)境變量中可用。
有關(guān)如何連接的詳細(xì)信息,請參閱http://code.google.com/p/selenium/wiki/ChromeDriver。
編輯:
是的,似乎是Python綁定中的一個錯誤,從路徑或環(huán)境變量中讀取chromedriver二進(jìn)制文件。似乎chromedriver不在您的路徑中,您必須將其作為參數(shù)傳遞給構(gòu)造函數(shù)。
import osfrom selenium import webdriver chromedriver = "/Users/adam/Downloads/chromedriver"os.environ["webdriver.chrome.driver"] = chromedriver driver = webdriver.Chrome(chromedriver)driver.get("http://stackoverflow.com")driver.quit()

慕田峪4524236
TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個贊
添加回答
舉報
0/150
提交
取消