Python-selenium:Protected Mode settings are not the same for all zones.

编码环境:
  gvim 7.4


运行环境:
  win7-32(en)powershell
  Python 2.7.11

代码:

# -*-* coding: utf-8 -*-
from selenium import webdriver
from time import sleep

# driver=webdriver.Chrome()
# driver=webdriver.Firefox()


def login163():
    url = 'http://mail.163.com/'
    user = 'user'
    pwd = 'pwd'
    browser = webdriver.Ie()
    browser.get(url)
    sleep(20)
    frame = browser.find_element_by_id("x-URS-iframe")
    browser.switch_to_frame(frame)
    browser.find_element_by_name( "email" ).clear()
    browser.find_element_by_name( "email" ).send_keys( user )
    browser.find_element_by_name( "password" ).send_keys( pwd )
    browser.find_element_by_id( "dologin" ).click()
    browser.switch_to_default_content()    
    return browser
    

if __name__ == '__main__':
    browser = login163()
    sleep(30)
    browser.quit()

运行后错误提示信息:

selenium.common.exceptions.WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.' 

法一

修改浏览器安全设置:

正如上面提示信息所说,Internet/本地Internet/受信任的站定/受限制的站点中的启用保护模式全部去掉勾,或者全部勾上

方法二

在生成webdriver对象之前,修改浏览器配置信息,如下:

#coding=utf-8
from selenium import webdriver

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
DesiredCapabilities.INTERNETEXPLORER['ignoreProtectedModeSettings'] = True

dr = webdriver.Ie()
dr.get("http://www.baidu.com")
...
dr.quit()




你可能感兴趣的:(Python)