2011-12-20 32 views
1

我一直在使用硒(Python Webdriver)刮網站。當我嘗試使用click()選項時,我得到了拒絕權限錯誤。全堆棧跟蹤:「權限被拒絕」錯誤廢墟硒刮

Traceback (most recent call last): 
    File "scrape.py", line 19, in <module> 
    subjectOptions[1].click() 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 45, in click 
    self._execute(Command.CLICK_ELEMENT) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 194, in _execute 
    return self._parent.execute(command, params) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 153, in execute 
    self.error_handler.check_response(response) 
    File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 147, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: u"'Error: Permission denied for <http://localhost/scrape_test> to get property HTMLDocument.compatMode' when calling method: [wdIMouse::move]" 

這是導致問題的代碼。我知道一個事實,我試圖點擊選項存在(基於print):

from selenium import webdriver 
from selenium.common.exceptions import TimeoutException 
from selenium.webdriver.support.ui import WebDriverWait #available since 2.4.0 
import time 

# Create a new instance of the FireFox driver 
driver = webdriver.Firefox() 

# go to the local version of the page for testing 
driver.get("http://localhost/scrape_test") 

# Find the select by ID, get its options 
selectElement = driver.find_element_by_id("CLASS_SRCH_WRK2_SUBJECT$65$") 
subjectOptions = selectElement.find_elements_by_tag_name("option") 

# Click the desired option 
subjectOptions[1].click() 

我使用的是Firefox 8.0.1在Mac OS X 10.7.2

+1

工作克服? – Zarkonnen 2011-12-20 19:59:47

+0

在問題 – babonk 2011-12-20 20:02:17

+0

上添加了什麼subjectOptions []可容納什麼? ** IF **它與js有關,嘗試在點擊 – 2011-12-20 20:13:34

回答

5

看起來像它的一個webdriver錯誤。從誰最後修改硒源代碼文件的一個程序員的最新log entry說:

This leads to permissions errors, which I've still been unable to reduce:

Error: Permission denied for http://www.finn.no to get property HTMLDocument.compatMode' when calling method: [wdIMouse::move]

有一個關於這個問題hereherehere一些討論。

根據討論,它應該可以在Firefox 7下正常工作。而且,this related issue意味着鏈接仍然被點擊,儘管有錯誤,所以它可能在try/except內部工作。

+0

這是正確的。把它放在try catch中可以解決問題 – 2011-12-29 04:45:22

+0

試着抓住這個問題似乎沒有爲我解決問題。它無一例外地越過那部分,但不會點擊它們。 – babonk 2011-12-30 02:12:07

+0

我嘗試過:option.click(),除了:pass' – babonk 2011-12-30 02:41:01

0

對於暫時還與您正在使用什麼版本的Firefox,並且對什麼操作系統提供了約here