2012-06-22 64 views
2

我試圖安裝python-硒綁定安裝Python硒綁定,它顯示下面錯誤通過看<a href="http://code.google.com/p/selenium/wiki/PythonBindings" rel="nofollow">here</a></p> <p>當我試圖導入下面的命令在Fedora

from selenium.firefox.webdriver import WebDriver 

錯誤結果:

from selenium.firefox.webdriver import WebDriver 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named firefox.webdriver 

我搜索了很多解決這個問題,但我沒有得到正確的例子要做到這一點,任何人都可以請提供給我的方式和上一個例子如何安裝python selenium綁定以及爲什麼返回上述錯誤。

在此先感謝..........

編輯: 我按下面的答案編輯我的代碼,並試圖下面,我得到了下面

>>> from selenium import webdriver 
>>> driver = webdriver.Firefox() 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 51, in __init__ 
    self.binary, timeout), 
    File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__ 
    self.binary.launch_browser(self.profile) 
    File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 44, in launch_browser 
    self._wait_until_connectable() 
    File "/usr/lib/python2.7/site-packages/selenium-2.21.3-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 81, in _wait_until_connectable 
    self._get_firefox_output()) 
selenium.common.exceptions.WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: *** LOG addons.xpi: startup\n*** LOG addons.xpi: checkForChanges\n*** LOG addons.xpi: Opening database\n*** LOG addons.xpi: No changes found\nFailed to dlopen /usr/lib/libX11.so.6\ndlerror says: /usr/lib/libX11.so.6: wrong ELF class: ELFCLASS32\n' 

並且還說有some crash in firefox 1.0....

回答

1

正如該頁所述,他們已重新組織該軟件包。使用我在此發佈的第二個代碼清單。

One advantage of using trunk as of writing, is the reorganization of the package. Previously, to initialize a browser you had to perform,

from selenium.firefox.webdriver import WebDriver 
driver = WebDriver() 

This has been changed, so now all that is required is:

from selenium import webdriver 
driver = webdriver.Firefox() 

Edit(對於新的錯誤):

你從沒有X顯示Linux服務器呢? Firefox需要一個顯示器來呈現它自己。看看PyVirtualDisplay運行「無頭」(沒有X)。

+0

我編輯了上面的代碼,我得到了我上面說過的arror。 –

+0

檢查我的帖子上的編輯。如果你運行的服務器不是X Display,你將不得不使用PyVirtualDisplay這樣的工具來運行它。 –

+0

我已經安裝了PyVirtualDisplay,我非常抱歉,我不知道如何使用X顯示器來運行,我做了與在該頁面中顯示的相同的操作,但仍然收到相同的錯誤。你可以請給我一個示例代碼如何刪除此錯誤。預先感謝 –

1

我在Fedora 17 64bits上遇到同樣的問題。 硒 - 與裝載問題x_ignore_nofocus.so 問題

硒失敗與以下錯誤啓動Firefox:

「的瀏覽器似乎已經離開我們可以連接之前。 輸出是:無法使用dlopen /usr/lib/libX11.so.6\ndlerror 說:/usr/lib/libX11.so.6:錯誤的ELF類:ELFCLASS32 \ n」

這是因爲x_ignore_nofocus庫試圖加載libX11的32位版本而不是64位。在我的系統有以下的libx11的版本:

find/| grep libX11.so.6 | xargs file 

/usr/lib64/libX11.so.6:符號鏈接libX11.so.6.3.0 /usr/lib64/libX11.so.6.3。 0:ELF 64位LSB共享對象,x86-64,版本1(SYSV),動態鏈接,剝離 /usr/lib/libX11.so.6:符號鏈接到`libX11.so.6.3.0' /usr/lib中/ libX11.so.6.3.0:ELF 32位LSB的共享對象,英特爾公司的80386,版本1(SYSV),動態鏈接,剝去

SOLUTION 更改符號鏈接/usr/lib/libX11.so .6指向64位版本/usr/lib64/libX11.so.6.3。0:

mv /usr/lib/libX11.so.6 /usr/lib/libX11.so.6.bak 
ln -s /usr/lib64/libX11.so.6.3.0 /usr/lib/libX11.so.6 

之後,硒開始工作。 Source

+0

偉大的發現,男人。此解決方案在F17,64b – KeatsKelleher

+0

上爲我工作,歡迎您將我的答案標記爲對您有用。 – Mounir

+1

雖然這可能在理論上回答這個問題,但我們希望您在回答中包含鏈接文章的基本部分,並提供[鏈接供參考](http://meta.stackexchange.com/q/8259)。如果做不到這一點,答案就會受到鏈接腐敗的威脅。 – Kev

相關問題