1 Selenium打开浏览器

【环境】

Selenium3.0.1+Python3.6+unittest

win7+IE10

1、打开FireFox浏览器

import unittest
from selenium import webdriver

class Testauto(unittest.TestCase):
    #打开Firefox浏览器
    def test_openbrower(self):
        browser = webdriver.Firefox()
        browser.get("http://www.baidu.com")

if __name__ == '__main__':
    unittest.main()

2、打开IE浏览器

import unittest
import os
from selenium import webdriver

class TestAutoMethods(unittest.TestCase):

    def test_openieBrower(self):
        #IE在非默认路径下时,需要设置路径
ie_driver
= os.path.abspath(r"C:Program Files (x86)Internet ExplorerIEDriverServer.exe") os.environ["webdriver.ie.driver"] = ie_driver driver = webdriver.Ie(ie_driver) driver.get("http://www.youdao.com") if __name__ == '__main__': unittest.main()

打开IE浏览器存在问题
【问题描述】

1、报错为“http.client.RemoteDisconnected: Remote end closed connection without response”

【解决方案】

待解决。

20170414补充该问题原因:

由于采用代理上网,所以python+selenium+ie不能够成功打开,这是在代理下,驱动的原理引起的。

可参考该文章介绍:

http://www.ltesting.net/ceshi/open/kygncsgj/selenium/2012/0307/204323.html

所以如果在代理下遇到该问题,就不要纠结了,直接用firefox吧。

 
原文地址:https://www.cnblogs.com/catleer/p/6268675.html