2016-11-06 94 views
5

在瓶上本地運行Selenium。我使用PhantomJS驅動程序。我以前有一個路徑錯誤:WebDriverException:消息:'phantomjs'可執行文件可能具有錯誤的權限

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. 

但是從另一個StackOverflow的問題找出後,我才知道,我必須要通過環境路徑作爲PhantomJS參數。下面的路徑是虛擬環境文件夾中phantomJS文件夾的路徑。

driver = webdriver.PhantomJS(executable_path='/Users/MyAcc/Documents/MYWEBAPP/venv/lib/python3.5/site-packages/selenium/webdriver/phantomjs') 

不過,我現在得到一個新的錯誤代碼:

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable may have wrong permissions. 

這裏就是我得到的,當我檢查路徑的文件權限。

total 40 
drwxr-xr-x 7 USER staff 238 Nov 6 00:07 . 
drwxr-xr-x 17 USER staff 578 Nov 6 00:03 .. 
[email protected] 1 USER staff 6148 Nov 6 00:07 .DS_Store 
-rw-r--r-- 1 USER staff 787 Oct 31 12:27 __init__.py 
drwxr-xr-x 5 USER staff 170 Oct 31 12:27 __pycache__ 
-rw-r--r-- 1 USER staff 2587 Oct 31 12:27 service.py 
-rw-r--r-- 1 USER staff 2934 Oct 31 12:27 webdriver.py 
+0

當你列出目錄'ls -al' - 'rwxrwxrwx'時有什麼權限? – furas

+0

'總40' 'drwxr-XR-X 7 USER人員238 11月6日0時07分.' 'drwxr-XR-×17 USER人員578 11月6日00:03 ..' '-rw-R --r - @ 1 USER staff 6148 Nov 6 00:07 .DS_Store' '-rw-r - r-- 1 USER staff 787 Oct 31 12:27 __init __。py' 'drwxr-xr-x 5 USER staff 170 Oct 31 12:27 __pycache__' '-rw -r - r-- 1 USER staff 2587 Oct 31 12:27 service.py' '-rw-r - r-- 1 USER staff 2934 Oct 31 12:27 webdriver.py' – Tahir

+0

你解決了這個問題嗎? Thasnk你 –

回答

0

executable_path = './phantomjs-2.1.1-linux-x86_64/bin/phantomjs'

service_log_path = './log/ghostdriver.log'

driver = webdriver.PhantomJS(executable_path=executable_path, service_log_path=service_log_path)

您可以同時使用相對路徑和絕對路徑。

0

selenium.common.exceptions.WebDriverException:消息:'phantomjs'可執行文件可能具有錯誤的權限。

這個錯誤,因爲phantomjs沒有執行權限,只要爲phantomjs - 2.1.1 - Linux的 - x86_64的/ bin中/ phantomjs添加執行權限,文件模式U + X phantomjs

希望你能幫助你

+0

歡迎來到堆棧溢出,不要發佈答案兩次,編輯你的第一個答案,並在那裏做出改變,花一些時間閱讀[如何寫一個答案](http://stackoverflow.com/help/how-to-回答)。 – Hizqeel

-1

奇怪的是,對我來說,它是通過將幻影放入/usr/local/share並添加一些符號鏈接來解決的。我跟着these steps

  • 招phantomjs文件夾/usr/local/share/
    • sudo mv phantomjs-2.1.1-linux-x86_64.tar.bz2 /usr/local/share/.
  • 創建符號鏈接:
    • sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs
    • sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs

我不是Linux專家,所以我不知道爲什麼這會產生變化。如果有人想參與,感覺自由。

1

我把phantomjs文件放入/usr/local/bin,它工作正常。

0

我在使用python + phanomjs之前遇到過這個問題。 解決方案: linux ---將幻影放入/ usr/local/share; windows ---將phantomjs放入/ python/scripts。 希望幫助

1

那麼我得到這個由下面的代碼解決:

瀏覽器= webdriver.PhantomJS(executable_path = 「/usr/local/Cellar/phantomjs/2.1.1/bin/phantomjs」)

+0

它也適用於我在Windows 10中。最後的「phantomjs」是phantomjs.exe,不是摺疊。 – Renke

相關問題