Skip to content

Instantly share code, notes, and snippets.

@AutomatedTester
Created July 1, 2011 19:10
Show Gist options
  • Select an option

  • Save AutomatedTester/1059183 to your computer and use it in GitHub Desktop.

Select an option

Save AutomatedTester/1059183 to your computer and use it in GitHub Desktop.
Using Selenium 2 To type into fields
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest
class TestHistory(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def tearDown(self):
self.driver.quit()
def test_that_we_can_access_history(self):
self.driver.get("http://localhost:9999/")
input_field = self.driver.find_element_by_id('gcliInput') #Assumed it was an ID
input_field.send_keys("echo there")
input_field.send_keys("O" + Keys.RETURN)
input_field.send_keys("echo there E" + Keys.RETURN)
input_field.send_keys("echo there N" + Keys.RETURN)
input_field.send_keys("&")
self.assertEqual("echo there", input_field.get_attribute("value"))
input_field.send_keys("&")
input_field.send_keys("echo hello (" )
self.assertEqual("echo there", input_field.get_attribute("value"))
input_field.send_keys("(")
self.assertEqual("", input_field.get_attribute("value"))
input_field.send_keys("(")
self.assertEqual("", input_field.get_attribute("value"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment