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()
I am getting this warning. What is wrong?
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>
It's a known bug:
http://code.google.com/p/selenium/issues/detail?id=5923
It's safe to ignore it though. If you're using Python 3, you can do:
unittest.main(warnings='ignore')
See Python 3 unittest docs.
In Python 2, you'd use something like this:
with warnings.catch_warnings(record=True):
unittest.main()
cf the Python 2 warnings docs
If you'll forgive the shameless self-promotion, there's lots more info on selenium in a wee book I've written, here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With