fork download
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.support.ui import Select
  4. from selenium.common.exceptions import NoSuchElementException
  5. import unittest, time, re
  6.  
  7. class Gary(unittest.TestCase):
  8. def setUp(self):
  9. self.driver = webdriver.Firefox()
  10. self.driver.implicitly_wait(30)
  11. self.base_url = "http://w...content-available-to-author-only...o.in/"
  12. self.verificationErrors = []
  13.  
  14. def test_gary(self):
  15. driver = self.driver
  16. driver.get(self.base_url + "/")
  17. driver.find_element_by_id("lst-ib").clear()
  18. driver.find_element_by_id("lst-ib").send_keys("selenium webdriver")
  19. driver.find_element_by_id("lst-ib").clear()
  20. driver.find_element_by_id("lst-ib").send_keys("selenium webdriver python")
  21. # ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
  22. driver.find_element_by_xpath("//ol[@id='rso']/li[10]/div/h3/a/em[2]").click()
  23. self.assertEqual("Selenium's WebDriver & Python: Dealing with script timeouts", driver.find_element_by_css_selector("h3").text)
  24.  
  25. def is_element_present(self, how, what):
  26. try: self.driver.find_element(by=how, value=what)
  27. except NoSuchElementException, e: return False
  28. return True
  29.  
  30. def tearDown(self):
  31. self.driver.quit()
  32. self.assertEqual([], self.verificationErrors)
  33.  
  34. if __name__ == "__main__":
  35. unittest.main()
  36.  
Runtime error #stdin #stdout #stderr 0s 23296KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 1, in <module>
ImportError: No module named selenium