1from selenium import webdriver
2from selenium.webdriver.common.keys import Keys
3
4driver = webdriver.Firefox()
5driver.get("http://www.python.org")
6assert "Python" in driver.title
7elem = driver.find_element_by_name("q")
8elem.clear()
9elem.send_keys("pycon")
10elem.send_keys(Keys.RETURN)
11assert "No results found." not in driver.page_source
12driver.close()
13
1from selenium import webdriver
2from selenium.webdriver.common.keys import Keys
3
4driver = webdriver.Firefox()
5driver.get("http://www.python.org")
6assert "Python" in driver.title
7elem = driver.find_element_by_name("q")
8elem.clear()
9elem.send_keys("pycon")
10elem.send_keys(Keys.RETURN)
11assert "No results found." not in driver.page_source
12driver.close()
1import unittest
2from selenium import webdriver
3import time
4
5
6class TestThree(unittest.TestCase):
7
8 def setUp(self):
9 self.startTime = time.time()
10
11 def test_url_fire(self):
12 time.sleep(2)
13 self.driver = webdriver.Firefox()
14 self.driver.get("https://app.simplegoods.co/i/IQCZADOY") # url associated with button click
15 button = self.driver.find_element_by_id("payment-submit").get_attribute("value")
16 self.assertEquals(u'Pay - $60.00', button)
17
18 def test_url_phantom(self):
19 time.sleep(1)
20 self.driver = webdriver.PhantomJS()
21 self.driver.get("https://app.simplegoods.co/i/IQCZADOY") # url associated with button click
22 button = self.driver.find_element_by_id("payment-submit").get_attribute("value")
23 self.assertEquals(u'Pay - $60.00', button)
24
25 def tearDown(self):
26 t = time.time() - self.startTime
27 print("%s: %.3f" % (self.id(), t))
28 self.driver.quit()
29
30if __name__ == '__main__':
31 suite = unittest.TestLoader().loadTestsFromTestCase(TestThree)
32 unittest.TextTestRunner(verbosity=0).run(suite)
33
1# SELENIUM:
2# - python library
3# - opens up your browser and physically interacts with elements
4# - used for task automation and web scraping