from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class Gary(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://w...content-available-to-author-only...o.in/"
self.verificationErrors = []
def test_gary(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("lst-ib").clear()
driver.find_element_by_id("lst-ib").send_keys("selenium webdriver")
driver.find_element_by_id("lst-ib").clear()
driver.find_element_by_id("lst-ib").send_keys("selenium webdriver python")
# ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
driver.find_element_by_xpath("//ol[@id='rso']/li[10]/div/h3/a/em[2]").click()
self.assertEqual("Selenium's WebDriver & Python: Dealing with script timeouts", driver.find_element_by_css_selector("h3").text)
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()