python selenium example doesn't work, says no module named Keys

python, selenium

Solution

From http://code.google.com/p/selenium/issues/detail?id=1491 :

from selenium.webdriver.common.keys import Keys

Problem

I installed selenium via pip on a windows machine. Just tryout out the sample on the website: ``` http://pypi.python.org/pypi/selenium from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.common.keys import Keys import time browser = webdriver.Firefox() # Get local session of firefox browser.get("http://www.yahoo.com") # Load page assert browser.title == "Yahoo!" elem = browser.find_element_by_name("p") # Find the query box elem.send_keys("selenium" + Keys.RETURN) time.sleep(0.2) # Let the page load, will be added to the API try: browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]") except NoSuchElementException: assert 0, "can't find seleniumhq" browser.close() ``` I changed from time to import time and the error it was giving for that went away, now I am getting: ``` Traceback (most recent call last): File "test.py", line 3, in module from selenium.common.keys import Keys ImportError: no module named Keys ``` Is the sample out of date?

Original source