解决python脚本连接终止问题_python – MaxRetryError:HTTPConnectionPool:超出最大重试次数(由ProtocolError引起(‘连接中止.’,错误(111,...

我有一个问题:我想测试“选择”和“输入”.我可以像下面的代码一样编写它:

原始代码:

12 class Sinaselecttest(unittest.TestCase):

13

14 def setUp(self):

15 binary = FirefoxBinary('/usr/local/firefox/firefox')

16 self.driver = webdriver.Firefox(firefox_binary=binary)

17

18 def test_select_in_sina(self):

19 driver = self.driver

20 driver.get("https://www.sina.com.cn/")

21 try:

22 WebDriverWait(driver,30).until(

23 ec.visibility_of_element_located((By.XPATH,"/html/body/div[9]/div/div[1]/form/div[3]/input"))

24 )

25 finally:

26 driver.quit()

# #测试select功能

27 select=Select(driver.find_element_by_xpath("//*[@id='slt_01']")).select_by_value("微博")

28 element=driver.find_element_by_xpath("/html/body/div[9]/div/div[1]/form/div[3]/input")

29 element.send_keys("杨幂")

30 driver.find_element_by_xpath("/html/body/div[9]/div/div[1]/form/input").click()

31 driver.implicitly_wait(5)

32

33

34

我想测试Selenium“select”函数.所以我选择sina网站选择一个选项并在textarea中输入文本.然后搜索它.但是当我运行这个测试时,它有错误:

Traceback (most recent call last):

File "test_sina_select.py", line 32, in tearDown

self.driver.close()

File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 688, in close

self.execute(Command.CLOSE)

File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute

response = self.command_executor.execute(driver_command, params)

File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 376, in execute

return self._request(command_info[0], url, body=data)

File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 399, in _request

resp = self._conn.request(method, url, body=body, headers=headers)

File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 68, in request

**urlopen_kw)

File "/usr/lib/python2.7/site-packages/urllib3/request.py", line 81, in request_encode_url

return self.urlopen(method, url, **urlopen_kw)

File "/usr/lib/python2.7/site-packages/urllib3/poolmanager.py", line 247, in urlopen

response = conn.urlopen(method, u.request_uri, **kw)

File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen

release_conn=release_conn, **response_kw)

File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen

release_conn=release_conn, **response_kw)

File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 617, in urlopen

release_conn=release_conn, **response_kw)

File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 597, in urlopen

_stacktrace=sys.exc_info()[2])

File "/usr/lib/python2.7/site-packages/urllib3/util/retry.py", line 271, in increment

raise MaxRetryError(_pool, url, error or ResponseError(cause))

MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=51379): Max retries exceeded with url: /session/2e64d2a1-3c7f-4221-96fe-9d0b1c102195/window (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))

----------------------------------------------------------------------

Ran 1 test in 72.106s

谁能告诉我为什么?谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值