Advertisement
Guest User

Untitled

a guest
Sep 6th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from selenium import webdriver
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.webdriver.support.ui import Select
  6. from selenium.common.exceptions import NoSuchElementException
  7. from selenium.common.exceptions import NoAlertPresentException
  8. import unittest, time, re
  9.  
  10. class WikimediaUseThisFile(unittest.TestCase):
  11. def setUp(self):
  12. self.driver = webdriver.Firefox()
  13. self.driver.implicitly_wait(30)
  14. self.base_url = "https://commons.wikimedia.org/"
  15. self.verificationErrors = []
  16. self.accept_next_alert = True
  17.  
  18. def test_wikimedia_use_this_file(self):
  19. driver = self.driver
  20. driver.get(self.base_url + "/wiki/File:Maitreya_Buddha%2C_Nubra.jpg")
  21. driver.find_element_by_css_selector("a[title=\"Use this file on the web\"] > b").click()
  22. driver.find_element_by_id("stockphoto_attribution_html").click()
  23. driver.find_element_by_id("stockphoto_attribution").click()
  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 is_alert_present(self):
  31. try: self.driver.switch_to_alert()
  32. except NoAlertPresentException, e: return False
  33. return True
  34.  
  35. def close_alert_and_get_its_text(self):
  36. try:
  37. alert = self.driver.switch_to_alert()
  38. alert_text = alert.text
  39. if self.accept_next_alert:
  40. alert.accept()
  41. else:
  42. alert.dismiss()
  43. return alert_text
  44. finally: self.accept_next_alert = True
  45.  
  46. def tearDown(self):
  47. self.driver.quit()
  48. self.assertEqual([], self.verificationErrors)
  49.  
  50. if __name__ == "__main__":
  51. unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement