python+selenium 编写第一个自动化脚本 Ie版
# coding=utf-8
from selenium import webdriver
driver = webdriver.Ie()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium2")
driver.find_element_by_id("su").click()
driver.quit()
敲入如上代码,将代码保存为baidu.py(注意Ie大小写)
下载ie浏览器驱动,下载后将驱动保存在与python.exe同一个目录下,
记得将python路径和pip路径放到path中
右击用python idle打开,按F5运行,运行报错,报错如下:
Traceback (most recent call last):
File "C:\Users\lish\Desktop\baidu.py", line 4, in <module>
driver = webdriver.Ie()
File "C:\Users\lish\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 82, in __init__
desired_capabilities=capabilities)
File "C:\Users\lish\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\lish\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\lish\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "C:\Users\lish\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
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.
解决方法:把安全下红色框内的四个选项都勾上,然后保存,重启浏览器,再次回到idle,按F5运行即可
上一篇: selenium测试环境搭建和编写第一个自动化脚本
下一篇: 凉拌洋葱这样做!不能错过的开胃小菜!