2013-07-16 74 views
3

我在IE using Selenium with python中遇到了自動執行保護設置的問題。Python保護設置IE

我發現了一個解決方案來自動化在java中的設置,但它不工作時,我改變它爲python。

我嘗試以下::

from selenium import webdriver 

caps=webdriver.DesiredCapabilites.INTERNETEXPLORER 
caps['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS']=True 
driver=webdriver.Ie(caps) 

這產生誤差相對於給出的說法。

當我使用driver = webdriver.Ie() 它說保護模式設置必須相同的所有區域。

任何人都可以幫我在python中使用硒自動化這個東西。

回答

4

documentation,在python-selenum,你應該使用設置稱爲 ignoreProtectedModeSettings

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 

caps = DesiredCapabilities.INTERNETEXPLORER 
caps['ignoreProtectedModeSettings'] = True 

driver = webdriver.Ie(capabilities=caps) 
+1

+1,但是你應該認真** **解決根本問題.... http://jimevansmusic.blogspot.co.uk/2012/08/youre -doing-it-wrong-protected-mode-and.html ....我的意思是,**不要這樣做!** – Arran

+0

感謝分享! – alecxe

+0

謝謝你的答案。 這個解決方案正在與IEDriverServer一起使用。 但是,當我嘗試使用這段代碼硒2.26左右,即可以打開沒有IEDriverServer,我無法做到這一點。 你能告訴我如何複製這個早期的硒版本,其中IEDriverServer是可選的 – user2587419

0

期望的能力在某些情況下無法正常工作。以下是使用winreg從註冊表中更改保護設置的方法。

從WinReg項進口*

def Enable_Protected_Mode(): 
    # SECURITY ZONES ARE AS FOLLOWS: 
    # 0 is the Local Machine zone 
    # 1 is the Intranet zone 
    # 2 is the Trusted Sites zone 
    # 3 is the Internet zone 
    # 4 is the Restricted Sites zone 
    # CHANGING THE SUBKEY VALUE "2500" TO DWORD 0 ENABLES PROTECTED MODE FOR THAT ZONE. 
    # IN THE CODE BELOW THAT VALUE IS WITHIN THE "SetValueEx" FUNCTION AT THE END AFTER "REG_DWORD". 
    #os.system("taskkill /F /IM iexplore.exe") 
    try: 
     keyVal = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1' 
     key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS) 
     SetValueEx(key, "2500", 0, REG_DWORD, 0) 
     print("enabled protected mode") 
    except Exception: 
     print("failed to enable protected mode")