gpt4 book ai didi

python - 警告(来自警告模块): ResourceWarning: unclosed using selenium

转载 作者:太空狗 更新时间:2023-10-29 17:39:40 25 4
gpt4 key购买 nike

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class PythonOrgSearch(unittest.TestCase):

def setUp(self):
self.driver = webdriver.Firefox()

def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
self.assertIn("Google", driver.title)

def tearDown(self):
self.driver.close()

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

我收到此警告。怎么了?

Warning (from warnings module):
File "C:\Python33\lib\site-packages\selenium-2.37.2-py3.3.egg\selenium\webdriver\firefox\firefox_binary.py", line 95
while not utils.is_connectable(self.profile.port):
ResourceWarning: unclosed <socket.socket object, fd=400, family=2, type=1, proto=0>

最佳答案

这是一个已知错误:

http://code.google.com/p/selenium/issues/detail?id=5923

不过忽略它是安全的。如果您使用的是 Python 3,您可以:

unittest.main(warnings='ignore')

参见 Python 3 unittest docs .

在 Python 2 中,你会使用这样的东西:

with warnings.catch_warnings(record=True):
unittest.main()

比照Python 2 warnings docs

如果您能原谅无耻的 self 推销,在我写的一本小书中有更多关于 Selenium 的信息,here .

关于python - 警告(来自警告模块): ResourceWarning: unclosed <socket. socket object, fd=404, family=2, type=1, proto=0> using selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20885561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com