Bug 1130979 - Changed hard-coded values in find_element() and find_elements() calls to constants from marionette_driver.by. draft
authorKim Brown <kbmoz1515@gmail.com>
Fri, 11 Mar 2016 21:36:14 -0500
changeset 339678 dc0cfddc7a88644e0915c9ac642ae132a55a7791
parent 338591 af7c0cb0798f5425d5d344cbaf0ac0ecb1a72a86
child 339679 ef393ae5ee90311832668604d3157523f793a9c5
push id12797
push userbmo:kbmoz1515@gmail.com
push dateSat, 12 Mar 2016 18:35:17 +0000
bugs1130979
milestone48.0a1
Bug 1130979 - Changed hard-coded values in find_element() and find_elements() calls to constants from marionette_driver.by. MozReview-Commit-ID: 2WqpSGLJGHc
testing/marionette/client/marionette_driver/date_time_value.py
testing/marionette/client/marionette_driver/marionette.py
testing/marionette/client/marionette_driver/selection.py
testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
testing/marionette/harness/marionette/tests/unit/test_about_pages.py
testing/marionette/harness/marionette/tests/unit/test_accessibility.py
testing/marionette/harness/marionette/tests/unit/test_anonymous_content.py
testing/marionette/harness/marionette/tests/unit/test_chrome_element_css.py
testing/marionette/harness/marionette/tests/unit/test_clearing.py
testing/marionette/harness/marionette/tests/unit/test_date_time_value.py
testing/marionette/harness/marionette/tests/unit/test_elementState.py
testing/marionette/harness/marionette/tests/unit/test_elementState_chrome.py
testing/marionette/harness/marionette/tests/unit/test_element_touch.py
testing/marionette/harness/marionette/tests/unit/test_elementsize.py
testing/marionette/harness/marionette/tests/unit/test_file_upload.py
testing/marionette/harness/marionette/tests/unit/test_gesture.py
testing/marionette/harness/marionette/tests/unit/test_getattr.py
testing/marionette/harness/marionette/tests/unit/test_implicit_waits.py
testing/marionette/harness/marionette/tests/unit/test_import_script.py
testing/marionette/harness/marionette/tests/unit/test_key_actions.py
testing/marionette/harness/marionette/tests/unit/test_modal_dialogs.py
testing/marionette/harness/marionette/tests/unit/test_mouse_action.py
testing/marionette/harness/marionette/tests/unit/test_multi_finger.py
testing/marionette/harness/marionette/tests/unit/test_navigation.py
testing/marionette/harness/marionette/tests/unit/test_position.py
testing/marionette/harness/marionette/tests/unit/test_rendered_element.py
testing/marionette/harness/marionette/tests/unit/test_screenshot.py
testing/marionette/harness/marionette/tests/unit/test_selected.py
testing/marionette/harness/marionette/tests/unit/test_selected_chrome.py
testing/marionette/harness/marionette/tests/unit/test_shadow_dom.py
testing/marionette/harness/marionette/tests/unit/test_single_finger.py
testing/marionette/harness/marionette/tests/unit/test_single_finger_desktop.py
testing/marionette/harness/marionette/tests/unit/test_switch_frame.py
testing/marionette/harness/marionette/tests/unit/test_switch_remote_frame.py
testing/marionette/harness/marionette/tests/unit/test_text.py
testing/marionette/harness/marionette/tests/unit/test_text_chrome.py
testing/marionette/harness/marionette/tests/unit/test_timeouts.py
testing/marionette/harness/marionette/tests/unit/test_typing.py
testing/marionette/harness/marionette/tests/unit/test_visibility.py
testing/marionette/harness/marionette/tests/unit/test_window_handles.py
testing/marionette/harness/marionette/tests/unit/test_window_management.py
testing/marionette/harness/marionette/tests/unit/test_window_switching.py
--- a/testing/marionette/client/marionette_driver/date_time_value.py
+++ b/testing/marionette/client/marionette_driver/date_time_value.py
@@ -5,17 +5,17 @@
 class DateTimeValue(object):
     """
     Interface for setting the value of HTML5 "date" and "time" input elements.
 
     Simple usage example:
 
     ::
 
-        element = marionette.find_element("id", "date-test")
+        element = marionette.find_element(By.ID, "date-test")
         dt_value = DateTimeValue(element)
         dt_value.date = datetime(1998, 6, 2)
 
     """
 
     def __init__(self, element):
         self.element = element
 
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -191,18 +191,18 @@ class Actions(object):
 
     ::
 
         # get html file
         testAction = marionette.absolute_url("testFool.html")
         # navigate to the file
         marionette.navigate(testAction)
         # find element1 and element2
-        element1 = marionette.find_element("id", "element1")
-        element2 = marionette.find_element("id", "element2")
+        element1 = marionette.find_element(By.ID, "element1")
+        element2 = marionette.find_element(By.ID, "element2")
         # create action object
         action = Actions(marionette)
         # add actions (press, wait, move, release) into the object
         action.press(element1).wait(5). move(element2).release()
         # fire all the added events
         action.perform()
     '''
 
@@ -1621,17 +1621,17 @@ class Marionette(object):
         You can use the `script_args` parameter to pass arguments to the
         script:
 
         ::
 
             result = marionette.execute_script("return arguments[0] + arguments[1];",
                                                script_args=[2, 3])
             assert result == 5
-            some_element = marionette.find_element("id", "someElement")
+            some_element = marionette.find_element(By.ID, "someElement")
             sid = marionette.execute_script("return arguments[0].id;", script_args=[some_element])
             assert some_element.get_attribute("id") == sid
 
         Scripts wishing to access non-standard properties of the window
         object must use window.wrappedJSObject:
 
         ::
 
--- a/testing/marionette/client/marionette_driver/selection.py
+++ b/testing/marionette/client/marionette_driver/selection.py
@@ -9,17 +9,17 @@ class SelectionManager(object):
 
     We call the blinking cursor (nsCaret) as cursor, and call AccessibleCaret as
     caret for short.
 
     Simple usage example:
 
     ::
 
-        element = marionette.find_element('id', 'input')
+        element = marionette.find_element(By.ID, 'input')
         sel = SelectionManager(element)
         sel.move_caret_to_front()
 
     '''
 
     def __init__(self, element):
         self.element = element
 
--- a/testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
+++ b/testing/marionette/harness/marionette/tests/unit/single_finger_functions.py
@@ -1,128 +1,130 @@
 from marionette_driver.marionette import Actions
 from marionette_driver.errors import TimeoutException
+from marionette_driver.by import By
+
 
 def wait_for_condition_else_raise(marionette, wait_for_condition, expected, script):
     try:
         wait_for_condition(lambda m: expected in m.execute_script(script))
     except TimeoutException as e:
         raise TimeoutException(e.msg + " got %s instead of %s" % (marionette.execute_script(script), expected))
 
 def press_release(marionette, times, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
     action = Actions(marionette)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action.press(button).release()
     # Insert wait between each press and release chain.
     for _ in range(times-1):
         action.wait(0.1)
         action.press(button).release()
     action.perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
 
 def move_element(marionette, wait_for_condition, expected1, expected2):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    ele = marionette.find_element("id", "button1")
-    drop = marionette.find_element("id", "button2")
+    ele = marionette.find_element(By.ID, "button1")
+    drop = marionette.find_element(By.ID, "button2")
     action = Actions(marionette)
     action.press(ele).move(drop).release()
     action.perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button2').innerHTML;")
 
 def move_element_offset(marionette, wait_for_condition, expected1, expected2):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    ele = marionette.find_element("id", "button1")
+    ele = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.press(ele).move_by_offset(0,150).move_by_offset(0, 150).release()
     action.perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button2').innerHTML;")
 
 def chain(marionette, wait_for_condition, expected1, expected2):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
     marionette.set_search_timeout(15000)
     action = Actions(marionette)
-    button1 = marionette.find_element("id", "button1")
+    button1 = marionette.find_element(By.ID, "button1")
     action.press(button1).perform()
-    button2 = marionette.find_element("id", "delayed")
+    button2 = marionette.find_element(By.ID, "delayed")
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
     action.move(button2).release().perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('delayed').innerHTML;")
 
 def chain_flick(marionette, wait_for_condition, expected1, expected2):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.flick(button, 0, 0, 0, 200).perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1,"return document.getElementById('button1').innerHTML;")
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2,"return document.getElementById('buttonFlick').innerHTML;")
 
 
 def wait(marionette, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
     action = Actions(marionette)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action.press(button).wait().release().perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
 
 def wait_with_value(marionette, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.press(button).wait(0.01).release()
     action.perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
 
 def context_menu(marionette, wait_for_condition, expected1, expected2):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.press(button).wait(5).perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected1, "return document.getElementById('button1').innerHTML;")
     action.release().perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected2, "return document.getElementById('button1').innerHTML;")
 
 def long_press_action(marionette, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.long_press(button, 5).perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
 
 def long_press_on_xy_action(marionette, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    html = marionette.find_element("tag name", "html")
-    button = marionette.find_element("id", "button1")
+    html = marionette.find_element(By.TAG_NAME, "html")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
 
     # Press the center of the button with respect to html.
     x = button.rect['x'] + button.rect['width'] / 2.0
     y = button.rect['y'] + button.rect['height'] / 2.0
     action.long_press(html, 5, x, y).perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
 
 def single_tap(marionette, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.tap(button).perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
 
 def double_tap(marionette, wait_for_condition, expected):
     testAction = marionette.absolute_url("testAction.html")
     marionette.navigate(testAction)
-    button = marionette.find_element("id", "button1")
+    button = marionette.find_element(By.ID, "button1")
     action = Actions(marionette)
     action.double_tap(button).perform()
     wait_for_condition_else_raise(marionette, wait_for_condition, expected, "return document.getElementById('button1').innerHTML;")
--- a/testing/marionette/harness/marionette/tests/unit/test_about_pages.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_about_pages.py
@@ -2,16 +2,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette.marionette_test import skip_if_e10s
 from marionette_driver.keys import Keys
 from marionette_driver.by import By
 
+
 class TestAboutPages(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         if self.marionette.session_capabilities['platformName'] == 'Darwin':
             self.mod_key = Keys.META
         else:
             self.mod_key = Keys.CONTROL
@@ -39,40 +40,40 @@ class TestAboutPages(MarionetteTestCase)
     def test_navigate_shortcut_key(self):
         self.marionette.navigate("about:preferences")
         self.marionette.navigate(self.remote_uri)
         self.marionette.navigate("about:blank")
 
         start_win = self.marionette.current_window_handle
         start_win_handles = self.marionette.window_handles
         with self.marionette.using_context("chrome"):
-            main_win = self.marionette.find_element("id", "main-window")
+            main_win = self.marionette.find_element(By.ID, "main-window")
             main_win.send_keys(self.mod_key, Keys.SHIFT, 'a')
 
         self.wait_for_condition(lambda mn: len(mn.window_handles) == 2)
         self.assertEqual(start_win, self.marionette.current_window_handle)
         [new_tab] = list(set(self.marionette.window_handles) - set(start_win_handles))
         self.marionette.switch_to_window(new_tab)
         self.wait_for_condition(lambda mn: mn.get_url() == "about:addons")
         self.marionette.close()
         self.marionette.switch_to_window(start_win)
 
     @skip_if_e10s
     def test_type_to_non_remote_tab(self):
         with self.marionette.using_context("chrome"):
-            urlbar = self.marionette.find_element('id', 'urlbar')
+            urlbar = self.marionette.find_element(By.ID, 'urlbar')
             urlbar.send_keys(self.mod_key + 'a')
             urlbar.send_keys(self.mod_key + 'x')
             urlbar.send_keys('about:preferences' + Keys.ENTER)
         self.wait_for_condition(lambda mn: mn.get_url() == "about:preferences")
 
     def test_type_to_remote_tab(self):
         self.marionette.navigate("about:preferences")
         with self.marionette.using_context("chrome"):
-            urlbar = self.marionette.find_element('id', 'urlbar')
+            urlbar = self.marionette.find_element(By.ID, 'urlbar')
             urlbar.send_keys(self.mod_key + 'a')
             urlbar.send_keys(self.mod_key + 'x')
             urlbar.send_keys(self.remote_uri + Keys.ENTER)
 
         self.wait_for_condition(lambda mn: mn.get_url() == self.remote_uri)
 
     def test_hang(self):
         self.marionette.set_context('chrome')
--- a/testing/marionette/harness/marionette/tests/unit/test_accessibility.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_accessibility.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.errors import (ElementNotAccessibleException,
                                       ElementNotVisibleException)
+from marionette_driver.by import By
 
 
 class TestAccessibility(MarionetteTestCase):
 
     # Elements that are accessible with and without the accessibliity API
     valid_elementIDs = [
         # Button1 is an accessible button with a valid accessible name
         # computed from subtree
@@ -69,17 +70,17 @@ class TestAccessibility(MarionetteTestCa
     # Elements that are enabled but otherwise disabled or not explorable via the accessibility API
     disabled_accessibility_elementIDs = ["button12", "button15", "button16"]
 
     # Elements that are reporting selected state
     valid_option_elementIDs = ["option1", "option2"]
 
     def run_element_test(self, ids, testFn):
         for id in ids:
-            element = self.marionette.find_element("id", id)
+            element = self.marionette.find_element(By.ID, id)
             testFn(element)
 
     def setup_accessibility(self, raisesAccessibilityExceptions=True, navigate=True):
         self.marionette.delete_session()
         self.marionette.start_session(
             {"raisesAccessibilityExceptions": raisesAccessibilityExceptions})
         # Navigate to test_accessibility.html
         if navigate:
--- a/testing/marionette/harness/marionette/tests/unit/test_anonymous_content.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_anonymous_content.py
@@ -3,16 +3,18 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 
 from marionette_driver.errors import NoSuchElementException
 from marionette_driver.expected import element_present
 from marionette_driver.marionette import HTMLElement
 from marionette_driver.wait import Wait
+from marionette_driver.by import By
+
 
 class TestAnonymousContent(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
         self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test_anonymous_content.xul', 'foo', 'chrome,centerscreen');")
         self.marionette.switch_to_window('foo')
@@ -20,44 +22,44 @@ class TestAnonymousContent(MarionetteTes
 
     def tearDown(self):
         self.assertNotEqual(self.win, self.marionette.current_window_handle)
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_switch_to_anonymous_frame(self):
-        self.marionette.find_element("id", "testAnonymousContentBox")
-        anon_browser_el = self.marionette.find_element("id", "browser")
+        self.marionette.find_element(By.ID, "testAnonymousContentBox")
+        anon_browser_el = self.marionette.find_element(By.ID, "browser")
         self.assertTrue("test_anonymous_content.xul" in self.marionette.get_url())
         self.marionette.switch_to_frame(anon_browser_el)
         self.assertTrue("test.xul" in self.marionette.get_url())
-        self.marionette.find_element("id", "testXulBox")
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "testAnonymousContentBox")
+        self.marionette.find_element(By.ID, "testXulBox")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "testAnonymousContentBox")
 
     def test_switch_to_anonymous_iframe(self):
-        self.marionette.find_element("id", "testAnonymousContentBox")
-        el = self.marionette.find_element("id", "container2")
-        anon_iframe_el = el.find_element("anon attribute", {"anonid": "iframe"})
+        self.marionette.find_element(By.ID, "testAnonymousContentBox")
+        el = self.marionette.find_element(By.ID, "container2")
+        anon_iframe_el = el.find_element(By.ANON_ATTRIBUTE, {"anonid": "iframe"})
         self.marionette.switch_to_frame(anon_iframe_el)
         self.assertTrue("test.xul" in self.marionette.get_url())
-        self.marionette.find_element("id", "testXulBox")
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, "id",
+        self.marionette.find_element(By.ID, "testXulBox")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID,
                           "testAnonymousContentBox")
 
     def test_find_anonymous_element_by_attribute(self):
-        el = Wait(self.marionette).until(element_present("id", "dia"))
-        self.assertEquals(HTMLElement, type(el.find_element("anon attribute", {"anonid": "buttons"})))
-        self.assertEquals(1, len(el.find_elements("anon attribute", {"anonid": "buttons"})))
+        el = Wait(self.marionette).until(element_present(By.ID, "dia"))
+        self.assertEquals(HTMLElement, type(el.find_element(By.ANON_ATTRIBUTE, {"anonid": "buttons"})))
+        self.assertEquals(1, len(el.find_elements(By.ANON_ATTRIBUTE, {"anonid": "buttons"})))
 
         with self.assertRaises(NoSuchElementException):
-            el.find_element("anon attribute", {"anonid": "nonexistent"})
-        self.assertEquals([], el.find_elements("anon attribute", {"anonid": "nonexistent"}))
+            el.find_element(By.ANON_ATTRIBUTE, {"anonid": "nonexistent"})
+        self.assertEquals([], el.find_elements(By.ANON_ATTRIBUTE, {"anonid": "nonexistent"}))
 
     def test_find_anonymous_children(self):
-        el = Wait(self.marionette).until(element_present("id", "dia"))
+        el = Wait(self.marionette).until(element_present(By.ID, "dia"))
         self.assertEquals(HTMLElement, type(el.find_element("anon", None)))
         self.assertEquals(2, len(el.find_elements("anon", None)))
 
-        el = self.marionette.find_element("id", "framebox")
+        el = self.marionette.find_element(By.ID, "framebox")
         with self.assertRaises(NoSuchElementException):
             el.find_element("anon", None)
         self.assertEquals([], el.find_elements("anon", None))
--- a/testing/marionette/harness/marionette/tests/unit/test_chrome_element_css.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_chrome_element_css.py
@@ -1,21 +1,22 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestChromeElementCSS(MarionetteTestCase):
 
     def test_we_can_get_css_value_on_chrome_element(self):
         self.marionette.navigate("about:blank")
         with self.marionette.using_context("chrome"):
-            element = self.marionette.find_element("id", "identity-icon")
+            element = self.marionette.find_element(By.ID, "identity-icon")
             favicon_image = element.value_of_css_property("list-style-image")
 
             self.assertIn("identity-icon.svg", favicon_image)
 
-            element = self.marionette.find_element("id", "identity-box")
+            element = self.marionette.find_element(By.ID, "identity-box")
             background_colour = element.value_of_css_property("background-color")
 
             self.assertEqual("transparent", background_colour)
--- a/testing/marionette/harness/marionette/tests/unit/test_clearing.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_clearing.py
@@ -1,69 +1,71 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.errors import InvalidElementStateException
+from marionette_driver.by import By
+
 
 class TestClear(MarionetteTestCase):
     def testWriteableTextInputShouldClear(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "writableTextInput")
+        element = self.marionette.find_element(By.ID, "writableTextInput")
         element.clear()
         self.assertEqual("", element.get_attribute("value"))
 
     def testTextInputShouldNotClearWhenReadOnly(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id","readOnlyTextInput")
+        element = self.marionette.find_element(By.ID,"readOnlyTextInput")
         try:
             element.clear()
             self.fail("Should not have been able to clear")
         except InvalidElementStateException:
             pass
 
     def testWritableTextAreaShouldClear(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id","writableTextArea")
+        element = self.marionette.find_element(By.ID,"writableTextArea")
         element.clear()
         self.assertEqual("", element.get_attribute("value"))
 
     def testTextAreaShouldNotClearWhenDisabled(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id","textAreaNotenabled")
+        element = self.marionette.find_element(By.ID,"textAreaNotenabled")
         try:
             element.clear()
             self.fail("Should not have been able to clear")
         except InvalidElementStateException:
             pass
 
     def testTextAreaShouldNotClearWhenReadOnly(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id","textAreaReadOnly")
+        element = self.marionette.find_element(By.ID,"textAreaReadOnly")
         try:
             element.clear()
             self.fail("Should not have been able to clear")
         except InvalidElementStateException:
             pass
 
     def testContentEditableAreaShouldClear(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id","content-editable")
+        element = self.marionette.find_element(By.ID,"content-editable")
         element.clear()
         self.assertEqual("", element.text)
 
     def testTextInputShouldNotClearWhenDisabled(self):
         test_html = self.marionette.absolute_url("test_clearing.html")
         self.marionette.navigate(test_html)
         try:
-            element = self.marionette.find_element("id","textInputnotenabled")
+            element = self.marionette.find_element(By.ID,"textInputnotenabled")
             self.assertFalse(element.is_enabled())
             element.clear()
             self.fail("Should not have been able to clear")
         except InvalidElementStateException:
             pass
--- a/testing/marionette/harness/marionette/tests/unit/test_date_time_value.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_date_time_value.py
@@ -1,27 +1,29 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from datetime import datetime
 from marionette_driver.date_time_value import DateTimeValue
+from marionette_driver.by import By
+
 
 class TestDateTime(MarionetteTestCase):
 
     def test_set_date(self):
         test_html = self.marionette.absolute_url("datetimePage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "date-test")
+        element = self.marionette.find_element(By.ID, "date-test")
         dt_value = DateTimeValue(element)
         dt_value.date = datetime(1998, 6, 2)
         self.assertEqual(element.get_attribute("value"), "1998-06-02")
 
     def test_set_time(self):
         test_html = self.marionette.absolute_url("datetimePage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "time-test")
+        element = self.marionette.find_element(By.ID, "time-test")
         dt_value = DateTimeValue(element)
         dt_value.time = datetime(1998, 11, 19, 9, 8, 7)
         self.assertEqual(element.get_attribute("value"), "09:08:07")
--- a/testing/marionette/harness/marionette/tests/unit/test_elementState.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_elementState.py
@@ -1,23 +1,24 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestState(MarionetteTestCase):
     def test_isEnabled(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        l = self.marionette.find_element("name", "myCheckBox")
+        l = self.marionette.find_element(By.NAME, "myCheckBox")
         self.assertTrue(l.is_enabled())
         self.marionette.execute_script("arguments[0].disabled = true;", [l])
         self.assertFalse(l.is_enabled())
 
     def test_isDisplayed(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        l = self.marionette.find_element("name", "myCheckBox")
+        l = self.marionette.find_element(By.NAME, "myCheckBox")
         self.assertTrue(l.is_displayed())
         self.marionette.execute_script("arguments[0].hidden = true;", [l])
         self.assertFalse(l.is_displayed())
--- a/testing/marionette/harness/marionette/tests/unit/test_elementState_chrome.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_elementState_chrome.py
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestStateChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
         self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', 'foo', 'chrome,centerscreen');")
@@ -16,28 +17,28 @@ class TestStateChrome(MarionetteTestCase
 
     def tearDown(self):
         self.assertNotEqual(self.win, self.marionette.current_window_handle)
         self.marionette.execute_script("window.close();")
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_isEnabled(self):
-        l = self.marionette.find_element("id", "textInput")
+        l = self.marionette.find_element(By.ID, "textInput")
         self.assertTrue(l.is_enabled())
         self.marionette.execute_script("arguments[0].disabled = true;", [l])
         self.assertFalse(l.is_enabled())
         self.marionette.execute_script("arguments[0].disabled = false;", [l])
 
     def test_can_get_element_rect(self):
-        l = self.marionette.find_element("id", "textInput")
+        l = self.marionette.find_element(By.ID, "textInput")
         rect = l.rect
         self.assertTrue(rect['x'] > 0)
         self.assertTrue(rect['y'] > 0)
 
     ''' Switched on in Bug 896043 to be turned on in Bug 896046
     def test_isDisplayed(self):
-        l = self.marionette.find_element("id", "textInput")
+        l = self.marionette.find_element(By.ID, "textInput")
         self.assertTrue(l.is_displayed())
         self.marionette.execute_script("arguments[0].hidden = true;", [l])
         self.assertFalse(l.is_displayed())
         self.marionette.execute_script("arguments[0].hidden = false;", [l])
     '''
\ No newline at end of file
--- a/testing/marionette/harness/marionette/tests/unit/test_element_touch.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_element_touch.py
@@ -1,33 +1,35 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.errors import MarionetteException
+from marionette_driver.by import By
+
 
 class testElementTouch(MarionetteTestCase):
     def test_touch(self):
       testAction = self.marionette.absolute_url("testAction.html")
       self.marionette.navigate(testAction)
-      button = self.marionette.find_element("id", "button1")
+      button = self.marionette.find_element(By.ID, "button1")
       button.tap()
       expected = "button1-touchstart-touchend-mousemove-mousedown-mouseup-click"
       self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button1').innerHTML;") == expected)
-      button = self.marionette.find_element("id", "button2")
+      button = self.marionette.find_element(By.ID, "button2")
       button.tap()
       expected = "button2-touchstart-touchend-mousemove-mousedown-mouseup-click"
       self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button2').innerHTML;") == expected)
 
     def test_invisible(self):
       testAction = self.marionette.absolute_url("testAction.html")
       self.marionette.navigate(testAction)
-      ele = self.marionette.find_element("id", "hidden")
+      ele = self.marionette.find_element(By.ID, "hidden")
       self.assertRaises(MarionetteException, ele.tap)
 
     def test_scrolling(self):
       testAction = self.marionette.absolute_url("testAction.html")
       self.marionette.navigate(testAction)
-      ele = self.marionette.find_element("id", "buttonScroll")
+      ele = self.marionette.find_element(By.ID, "buttonScroll")
       ele.tap()
       expected = "buttonScroll-touchstart-touchend-mousemove-mousedown-mouseup-click"
       self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('buttonScroll').innerHTML;") == expected)
--- a/testing/marionette/harness/marionette/tests/unit/test_elementsize.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_elementsize.py
@@ -1,20 +1,21 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette.marionette_test import MarionetteTestCase, skip_if_b2g
+from marionette_driver.by import By
 
 
 class TestElementSize(MarionetteTestCase):
     def testShouldReturnTheSizeOfALink(self):
         test_html = self.marionette.absolute_url("testSize.html")
         self.marionette.navigate(test_html)
-        shrinko = self.marionette.find_element('id', 'linkId')
+        shrinko = self.marionette.find_element(By.ID, 'linkId')
         size = shrinko.rect
         self.assertTrue(size['width'] > 0)
         self.assertTrue(size['height'] > 0)
 
 
 @skip_if_b2g
 class TestElementSizeChrome(MarionetteTestCase):
     def setUp(self):
@@ -32,12 +33,12 @@ class TestElementSizeChrome(MarionetteTe
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def testShouldReturnTheSizeOfAnInput(self):
         wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
-        shrinko = self.marionette.find_element('id', 'textInput')
+        shrinko = self.marionette.find_element(By.ID, 'textInput')
         size = shrinko.rect
         self.assertTrue(size['width'] > 0)
         self.assertTrue(size['height'] > 0)
--- a/testing/marionette/harness/marionette/tests/unit/test_file_upload.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_file_upload.py
@@ -102,17 +102,17 @@ class TestFileUpload(MarionetteTestCase)
             f.flush()
             self.input.send_keys(f.name)
             self.submit.click()
 
         Wait(self.marionette).until(lambda m: m.get_url() != url)
         self.assertIn("multipart/form-data", self.body.text)
 
     def find_inputs(self):
-        return self.marionette.find_elements("tag name", "input")
+        return self.marionette.find_elements(By.TAG_NAME, "input")
 
     @property
     def input(self):
         return self.find_inputs()[0]
 
     @property
     def submit(self):
         return self.find_inputs()[1]
--- a/testing/marionette/harness/marionette/tests/unit/test_gesture.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_gesture.py
@@ -1,36 +1,38 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette.gestures import smooth_scroll
+from marionette_driver.by import By
+
 
 class testGestures(MarionetteTestCase):
     check_in_viewport = """
         function elementInViewport(el) {
           let rect = el.getBoundingClientRect();
           return (rect.top >= window.pageYOffset &&
                  rect.left >= window.pageXOffset &&
                  rect.bottom <= (window.pageYOffset + window.innerHeight) &&
                  rect.right <= (window.pageXOffset + window.innerWidth)
          );   
         };
     """
     def test_smooth_scroll(self):
         testAction = self.marionette.absolute_url("testAction.html")
         self.marionette.navigate(testAction)
-        button = self.marionette.find_element("id", "button2")
+        button = self.marionette.find_element(By.ID, "button2")
         self.assertFalse(self.marionette.execute_script("%s; return elementInViewport(document.getElementById('buttonScroll'));" % self.check_in_viewport))
         smooth_scroll(self.marionette, button, "y",  -1, 800)
-        buttonScroll = self.marionette.find_element("id", "buttonScroll")
+        buttonScroll = self.marionette.find_element(By.ID, "buttonScroll")
         self.wait_for_condition(lambda m: m.execute_script("%s; return elementInViewport(arguments[0]);" % self.check_in_viewport, [buttonScroll]) == True)
         self.assertEqual("button2-touchstart", self.marionette.execute_script("return document.getElementById('button2').innerHTML;"))
 
     """
     #This test doesn't manipulate the page, filed Bug 870377 about it.
     def test_pinch(self):
         testAction = self.marionette.absolute_url("testAction.html")
         self.marionette.navigate(testAction)
-        button = self.marionette.find_element("id", "button1")
+        button = self.marionette.find_element(By.ID, "button1")
         pinch(self.marionette, button, 0, 0, 0, 0, 0, -50, 0, 50)
     """
--- a/testing/marionette/harness/marionette/tests/unit/test_getattr.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_getattr.py
@@ -1,19 +1,20 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestGetAttribute(MarionetteTestCase):
     def test_getAttribute(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        l = self.marionette.find_element("id", "mozLink")
+        l = self.marionette.find_element(By.ID, "mozLink")
         self.assertEqual("mozLink", l.get_attribute("id"))
 
     def test_that_we_can_return_a_boolean_attribute_correctly(self):
         test_html = self.marionette.absolute_url("html5/boolean_attributes.html")
         self.marionette.navigate(test_html)
-        disabled = self.marionette.find_element("id", "disabled")
+        disabled = self.marionette.find_element(By.ID, "disabled")
         self.assertEqual('true', disabled.get_attribute("disabled"))
--- a/testing/marionette/harness/marionette/tests/unit/test_implicit_waits.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_implicit_waits.py
@@ -1,28 +1,30 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.errors import NoSuchElementException
+from marionette_driver.by import By
+
 
 class TestImplicitWaits(MarionetteTestCase):
     def testShouldImplicitlyWaitForASingleElement(self):
         test_html = self.marionette.absolute_url("test_dynamic.html")
         self.marionette.navigate(test_html)
-        add = self.marionette.find_element("id", "adder")
+        add = self.marionette.find_element(By.ID, "adder")
         self.marionette.set_search_timeout("30000")
         add.click()
         # All is well if this doesnt throw
-        self.marionette.find_element("id", "box0")
+        self.marionette.find_element(By.ID, "box0")
 
     def testShouldStillFailToFindAnElementWhenImplicitWaitsAreEnabled(self):
         test_html = self.marionette.absolute_url("test_dynamic.html")
         self.marionette.navigate(test_html)
         self.marionette.set_search_timeout("3000")
         try:
-            self.marionette.find_element("id", "box0")
+            self.marionette.find_element(By.ID, "box0")
             self.fail("Should have thrown a a NoSuchElementException")
         except NoSuchElementException:
             pass
         except Exception:
             self.fail("Should have thrown a NoSuchElementException")
--- a/testing/marionette/harness/marionette/tests/unit/test_import_script.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_import_script.py
@@ -1,16 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
 
 from marionette.marionette_test import MarionetteTestCase, skip_if_chrome
 from marionette_driver.errors import JavascriptException
+from marionette_driver.by import By
+
 
 class TestImportScriptContent(MarionetteTestCase):
     contexts = set(["chrome", "content"])
 
     script_file = os.path.abspath(
         os.path.join(__file__, os.path.pardir, "importscript.js"))
     another_script_file = os.path.abspath(
         os.path.join(__file__, os.path.pardir, "importanotherscript.js"))
@@ -100,17 +102,17 @@ class TestImportScriptContent(Marionette
         self.assert_defined("testFunc")
         self.assert_defined("testAnotherFunc")
 
     @skip_if_chrome
     def test_imports_apply_globally(self):
         self.marionette.navigate(
             self.marionette.absolute_url("test_windows.html"))
         original_window = self.marionette.current_window_handle
-        self.marionette.find_element("link text", "Open new window").click()
+        self.marionette.find_element(By.LINK_TEXT, "Open new window").click()
 
         windows = set(self.marionette.window_handles)
         print "windows=%s" % windows
         new_window = windows.difference([original_window]).pop()
         self.marionette.switch_to_window(new_window)
 
         self.marionette.import_script(self.script_file)
         self.marionette.close()
--- a/testing/marionette/harness/marionette/tests/unit/test_key_actions.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_key_actions.py
@@ -1,27 +1,29 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette.marionette_test import MarionetteTestCase, skip_if_b2g
 from marionette_driver.keys import Keys
 from marionette_driver.marionette import Actions
+from marionette_driver.by import By
+
 
 class TestKeyActions(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         if self.marionette.session_capabilities['platformName'] == 'Darwin':
             self.mod_key = Keys.META
         else:
             self.mod_key = Keys.CONTROL
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        self.reporter_element = self.marionette.find_element("id", "keyReporter")
+        self.reporter_element = self.marionette.find_element(By.ID, "keyReporter")
         self.reporter_element.click()
         self.key_action = Actions(self.marionette)
 
     @property
     def key_reporter_value(self):
         return self.reporter_element.get_attribute('value')
 
     def test_key_action_basic_input(self):
@@ -64,17 +66,17 @@ class TestKeyActions(MarionetteTestCase)
                         .key_down('a')
                         .wait(.5)
                         .key_down('x')
                         .perform())
         self.assertEqual(self.key_reporter_value, "")
 
     @skip_if_b2g
     def test_open_in_new_window_shortcut(self):
-        el = self.marionette.find_element('id', 'updatediv')
+        el = self.marionette.find_element(By.ID, 'updatediv')
         start_win = self.marionette.current_chrome_window_handle
         (self.key_action.key_down(Keys.SHIFT)
                         .press(el)
                         .release()
                         .key_up(Keys.SHIFT)
                         .perform())
         self.wait_for_condition(
             lambda mn: len(self.marionette.window_handles) == 2)
--- a/testing/marionette/harness/marionette/tests/unit/test_modal_dialogs.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_modal_dialogs.py
@@ -1,16 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette.marionette_test import MarionetteTestCase, skip_if_e10s
 from marionette_driver.errors import NoAlertPresentException, ElementNotVisibleException
 from marionette_driver.marionette import Alert
 from marionette_driver.wait import Wait
+from marionette_driver.by import By
+
 
 class TestTabModals(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.enforce_gecko_prefs({"prompts.tab_modal.enabled": True})
         self.marionette.navigate(self.marionette.absolute_url('modal_dialogs.html'))
 
@@ -29,160 +31,160 @@ class TestTabModals(MarionetteTestCase):
     def wait_for_alert(self):
         Wait(self.marionette).until(lambda _: self.alert_present())
 
     def test_no_alert_raises(self):
         self.assertRaises(NoAlertPresentException, Alert(self.marionette).accept)
         self.assertRaises(NoAlertPresentException, Alert(self.marionette).dismiss)
 
     def test_alert_accept(self):
-        self.marionette.find_element('id', 'modal-alert').click()
+        self.marionette.find_element(By.ID, 'modal-alert').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.accept()
 
     def test_alert_dismiss(self):
-        self.marionette.find_element('id', 'modal-alert').click()
+        self.marionette.find_element(By.ID, 'modal-alert').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.dismiss()
 
     def test_confirm_accept(self):
-        self.marionette.find_element('id', 'modal-confirm').click()
+        self.marionette.find_element(By.ID, 'modal-confirm').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.accept()
-        self.wait_for_condition(lambda mn: mn.find_element('id', 'confirm-result').text == 'true')
+        self.wait_for_condition(lambda mn: mn.find_element(By.ID, 'confirm-result').text == 'true')
 
     def test_confirm_dismiss(self):
-        self.marionette.find_element('id', 'modal-confirm').click()
+        self.marionette.find_element(By.ID, 'modal-confirm').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.dismiss()
-        self.wait_for_condition(lambda mn: mn.find_element('id', 'confirm-result').text == 'false')
+        self.wait_for_condition(lambda mn: mn.find_element(By.ID, 'confirm-result').text == 'false')
 
     def test_prompt_accept(self):
-        self.marionette.find_element('id', 'modal-prompt').click()
+        self.marionette.find_element(By.ID, 'modal-prompt').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.accept()
-        self.wait_for_condition(lambda mn: mn.find_element('id', 'prompt-result').text == '')
+        self.wait_for_condition(lambda mn: mn.find_element(By.ID, 'prompt-result').text == '')
 
     def test_prompt_dismiss(self):
-        self.marionette.find_element('id', 'modal-prompt').click()
+        self.marionette.find_element(By.ID, 'modal-prompt').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.dismiss()
-        self.wait_for_condition(lambda mn: mn.find_element('id', 'prompt-result').text == 'null')
+        self.wait_for_condition(lambda mn: mn.find_element(By.ID, 'prompt-result').text == 'null')
 
     def test_alert_text(self):
         with self.assertRaises(NoAlertPresentException):
             alert = self.marionette.switch_to_alert()
             alert.text
-        self.marionette.find_element('id', 'modal-alert').click()
+        self.marionette.find_element(By.ID, 'modal-alert').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         self.assertEqual(alert.text, 'Marionette alert')
         alert.accept()
 
     def test_prompt_text(self):
         with self.assertRaises(NoAlertPresentException):
             alert = self.marionette.switch_to_alert()
             alert.text
-        self.marionette.find_element('id', 'modal-prompt').click()
+        self.marionette.find_element(By.ID, 'modal-prompt').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         self.assertEqual(alert.text, 'Marionette prompt')
         alert.accept()
 
     def test_confirm_text(self):
         with self.assertRaises(NoAlertPresentException):
             alert = self.marionette.switch_to_alert()
             alert.text
-        self.marionette.find_element('id', 'modal-confirm').click()
+        self.marionette.find_element(By.ID, 'modal-confirm').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         self.assertEqual(alert.text, 'Marionette confirm')
         alert.accept()
 
     def test_set_text_throws(self):
         self.assertRaises(NoAlertPresentException, Alert(self.marionette).send_keys, "Foo")
-        self.marionette.find_element('id', 'modal-alert').click()
+        self.marionette.find_element(By.ID, 'modal-alert').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         self.assertRaises(ElementNotVisibleException, alert.send_keys, "Foo")
         alert.accept()
 
     def test_set_text_accept(self):
-        self.marionette.find_element('id', 'modal-prompt').click()
+        self.marionette.find_element(By.ID, 'modal-prompt').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.send_keys("Some text!");
         alert.accept()
-        self.wait_for_condition(lambda mn: mn.find_element('id', 'prompt-result').text == 'Some text!')
+        self.wait_for_condition(lambda mn: mn.find_element(By.ID, 'prompt-result').text == 'Some text!')
 
     def test_set_text_dismiss(self):
-        self.marionette.find_element('id', 'modal-prompt').click()
+        self.marionette.find_element(By.ID, 'modal-prompt').click()
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         alert.send_keys("Some text!");
         alert.dismiss()
-        self.wait_for_condition(lambda mn: mn.find_element('id', 'prompt-result').text == 'null')
+        self.wait_for_condition(lambda mn: mn.find_element(By.ID, 'prompt-result').text == 'null')
 
     def test_onbeforeunload_dismiss(self):
         start_url = self.marionette.get_url()
-        self.marionette.find_element('id', 'onbeforeunload-handler').click()
+        self.marionette.find_element(By.ID, 'onbeforeunload-handler').click()
         self.wait_for_condition(
             lambda mn: mn.execute_script("""
               return window.onbeforeunload !== null;
             """))
         self.marionette.navigate("about:blank")
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         self.assertTrue(alert.text.startswith("This page is asking you to confirm"))
         alert.dismiss()
         self.assertTrue(self.marionette.get_url().startswith(start_url))
 
     def test_onbeforeunload_accept(self):
-        self.marionette.find_element('id', 'onbeforeunload-handler').click()
+        self.marionette.find_element(By.ID, 'onbeforeunload-handler').click()
         self.wait_for_condition(
             lambda mn: mn.execute_script("""
               return window.onbeforeunload !== null;
             """))
         self.marionette.navigate("about:blank")
         self.wait_for_alert()
         alert = self.marionette.switch_to_alert()
         self.assertTrue(alert.text.startswith("This page is asking you to confirm"))
         alert.accept()
         self.wait_for_condition(lambda mn: mn.get_url() == "about:blank")
 
     @skip_if_e10s
     def test_unrelated_command_when_alert_present(self):
-        click_handler = self.marionette.find_element('id', 'click-handler')
-        text = self.marionette.find_element('id', 'click-result').text
+        click_handler = self.marionette.find_element(By.ID, 'click-handler')
+        text = self.marionette.find_element(By.ID, 'click-result').text
         self.assertEqual(text, '')
 
-        self.marionette.find_element('id', 'modal-alert').click()
+        self.marionette.find_element(By.ID, 'modal-alert').click()
         self.wait_for_alert()
 
         # Commands succeed, but because the dialog blocks the event loop,
         # our actions aren't reflected on the page.
-        text = self.marionette.find_element('id', 'click-result').text
+        text = self.marionette.find_element(By.ID, 'click-result').text
         self.assertEqual(text, '')
         click_handler.click()
-        text = self.marionette.find_element('id', 'click-result').text
+        text = self.marionette.find_element(By.ID, 'click-result').text
         self.assertEqual(text, '')
 
         alert = self.marionette.switch_to_alert()
         alert.accept()
 
         Wait(self.marionette).until(lambda _: not self.alert_present())
 
         click_handler.click()
-        text = self.marionette.find_element('id', 'click-result').text
+        text = self.marionette.find_element(By.ID, 'click-result').text
         self.assertEqual(text, 'result')
 
 
 class TestGlobalModals(TestTabModals):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.enforce_gecko_prefs({"prompts.tab_modal.enabled": False})
--- a/testing/marionette/harness/marionette/tests/unit/test_mouse_action.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_mouse_action.py
@@ -2,16 +2,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.marionette import Actions
 from marionette_driver.keys import Keys
 from marionette_driver.by import By
 
+
 class TestMouseAction(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         if self.marionette.session_capabilities['platformName'] == 'Darwin':
             self.mod_key = Keys.META
         else:
             self.mod_key = Keys.CONTROL
@@ -32,17 +33,17 @@ class TestMouseAction(MarionetteTestCase
         self.action.click(el).perform()
 
     def test_double_click_action(self):
         test_html = self.marionette.absolute_url("double_click.html")
         self.marionette.navigate(test_html)
         el = self.marionette.find_element(By.ID, 'one-word-div')
         self.action.double_click(el).perform()
         el.send_keys(self.mod_key + 'c')
-        rel = self.marionette.find_element("id", "input-field")
+        rel = self.marionette.find_element(By.ID, "input-field")
         rel.send_keys(self.mod_key + 'v')
         self.assertEqual(rel.get_attribute('value'), 'zyxw')
 
     def test_context_click_action(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
         click_el = self.marionette.find_element(By.ID, 'resultContainer')
 
--- a/testing/marionette/harness/marionette/tests/unit/test_multi_finger.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_multi_finger.py
@@ -1,56 +1,58 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.marionette import MultiActions, Actions
+from marionette_driver.by import By
+
 
 class testMultiFinger(MarionetteTestCase):
     def test_move_element(self):
       testAction = self.marionette.absolute_url("testAction.html")
       self.marionette.navigate(testAction)
-      start = self.marionette.find_element("id", "button1")
-      drop = self.marionette.find_element("id", "button2")
-      ele = self.marionette.find_element("id", "button3")
+      start = self.marionette.find_element(By.ID, "button1")
+      drop = self.marionette.find_element(By.ID, "button2")
+      ele = self.marionette.find_element(By.ID, "button3")
       multi_action = MultiActions(self.marionette)
       action1 = Actions(self.marionette)
       action2 = Actions(self.marionette)
       action1.press(start).move(drop).wait(3).release()
       action2.press(ele).wait().release()
       multi_action.add(action1).add(action2).perform()
       expected = "button1-touchstart"
       self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button1').innerHTML;") == expected)
       self.assertEqual("button2-touchmove-touchend", self.marionette.execute_script("return document.getElementById('button2').innerHTML;"))
       self.assertTrue("button3-touchstart-touchend" in self.marionette.execute_script("return document.getElementById('button3').innerHTML;"))
 
     def test_move_offset_element(self):
       testAction = self.marionette.absolute_url("testAction.html")
       self.marionette.navigate(testAction)
-      start = self.marionette.find_element("id", "button1")
-      ele = self.marionette.find_element("id", "button3")
+      start = self.marionette.find_element(By.ID, "button1")
+      ele = self.marionette.find_element(By.ID, "button3")
       multi_action = MultiActions(self.marionette)
       action1 = Actions(self.marionette)
       action2 = Actions(self.marionette)
       action1.press(start).move_by_offset(0,300).wait().release()
       action2.press(ele).wait(5).release()
       multi_action.add(action1).add(action2).perform()
       expected = "button1-touchstart"
       self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button1').innerHTML;") == expected)
       self.assertEqual("button2-touchmove-touchend", self.marionette.execute_script("return document.getElementById('button2').innerHTML;"))
       self.assertTrue("button3-touchstart-touchend" in self.marionette.execute_script("return document.getElementById('button3').innerHTML;"))
 
     def test_three_fingers(self):
       testAction = self.marionette.absolute_url("testAction.html")
       self.marionette.navigate(testAction)
-      start_one = self.marionette.find_element("id", "button1")
-      start_two = self.marionette.find_element("id", "button2")
-      element1 = self.marionette.find_element("id", "button3")
-      element2 = self.marionette.find_element("id", "button4")
+      start_one = self.marionette.find_element(By.ID, "button1")
+      start_two = self.marionette.find_element(By.ID, "button2")
+      element1 = self.marionette.find_element(By.ID, "button3")
+      element2 = self.marionette.find_element(By.ID, "button4")
       multi_action = MultiActions(self.marionette)
       action1 = Actions(self.marionette)
       action2 = Actions(self.marionette)
       action3 = Actions(self.marionette)
       action1.press(start_one).move_by_offset(0,300).release()
       action2.press(element1).wait().wait(5).release()
       action3.press(element2).wait().wait().release()
       multi_action.add(action1).add(action2).add(action3).perform()
--- a/testing/marionette/harness/marionette/tests/unit/test_navigation.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_navigation.py
@@ -1,14 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette.marionette_test import MarionetteTestCase, skip_if_b2g
 from marionette_driver.errors import MarionetteException, TimeoutException
+from marionette_driver.by import By
+
 
 class TestNavigate(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.execute_script("window.location.href = 'about:blank'")
         self.assertEqual("about:blank", self.location_href)
         self.test_doc = self.marionette.absolute_url("test.html")
         self.iframe_doc = self.marionette.absolute_url("test_iframe.html")
@@ -27,17 +29,17 @@ class TestNavigate(MarionetteTestCase):
     def test_navigate_chrome_error(self):
         with self.marionette.using_context("chrome"):
             self.assertRaisesRegexp(MarionetteException, "Cannot navigate in chrome context",
                                     self.marionette.navigate, "about:blank")
 
     def test_get_current_url_returns_top_level_browsing_context_url(self):
         self.marionette.navigate(self.iframe_doc)
         self.assertEqual(self.iframe_doc, self.location_href)
-        frame = self.marionette.find_element("css selector", "#test_iframe")
+        frame = self.marionette.find_element(By.CSS_SELECTOR, "#test_iframe")
         self.marionette.switch_to_frame(frame)
         self.assertEqual(self.iframe_doc, self.marionette.get_url())
 
     def test_get_current_url(self):
         self.marionette.navigate(self.test_doc)
         self.assertEqual(self.test_doc, self.marionette.get_url())
         self.marionette.navigate("about:blank")
         self.assertEqual("about:blank", self.marionette.get_url())
@@ -108,31 +110,31 @@ class TestNavigate(MarionetteTestCase):
         self.marionette.navigate(self.marionette.absolute_url("test.html"))
         self.marionette.navigate("about:blocked")
         self.assertEqual(self.marionette.get_url(), "about:blocked")
 
     def test_find_element_state_complete(self):
         self.marionette.navigate(self.test_doc)
         state = self.marionette.execute_script("return window.document.readyState")
         self.assertEqual("complete", state)
-        self.assertTrue(self.marionette.find_element("id", "mozLink"))
+        self.assertTrue(self.marionette.find_element(By.ID, "mozLink"))
 
     def test_should_throw_a_timeoutexception_when_loading_page(self):
         try:
             self.marionette.timeouts("page load", 0)
             self.marionette.navigate(self.test_doc)
-            self.assertTrue(self.marionette.find_element("id", "mozLink"))
+            self.assertTrue(self.marionette.find_element(By.ID, "mozLink"))
             self.fail("Should have thrown a MarionetteException")
         except TimeoutException as e:
             self.assertTrue("Error loading page, timed out" in str(e))
         except Exception as e:
             import traceback
             print traceback.format_exc()
             self.fail("Should have thrown a TimeoutException instead of %s" % type(e))
 
     def test_navigate_iframe(self):
         self.marionette.navigate(self.iframe_doc)
         self.assertTrue('test_iframe.html' in self.marionette.get_url())
-        self.assertTrue(self.marionette.find_element("id", "test_iframe"))
+        self.assertTrue(self.marionette.find_element(By.ID, "test_iframe"))
 
     @property
     def location_href(self):
         return self.marionette.execute_script("return window.location.href")
--- a/testing/marionette/harness/marionette/tests/unit/test_position.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_position.py
@@ -1,13 +1,14 @@
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestPosition(MarionetteTestCase):
 
     def test_should_get_element_position_back(self):
         test_url = self.marionette.absolute_url('rectangles.html')
         self.marionette.navigate(test_url)
 
-        r2 = self.marionette.find_element('id', "r2")
+        r2 = self.marionette.find_element(By.ID, "r2")
         location = r2.rect
         self.assertEqual(11, location['x'])
         self.assertEqual(10, location['y'])
--- a/testing/marionette/harness/marionette/tests/unit/test_rendered_element.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_rendered_element.py
@@ -9,24 +9,25 @@
 #
 #Unless required by applicable law or agreed to in writing, software
 #distributed under the License is distributed on an "AS IS" BASIS,
 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 #See the License for the specific language governing permissions and
 #limitations under the License.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class RenderedElementTests(MarionetteTestCase):
 
     def testWeCanGetComputedStyleValueOnElement(self):
         test_url = self.marionette.absolute_url('javascriptPage.html')
         self.marionette.navigate(test_url)
-        element = self.marionette.find_element('id', "green-parent")
+        element = self.marionette.find_element(By.ID, "green-parent")
         backgroundColour = element.value_of_css_property("background-color")
 
         self.assertEqual("rgb(0, 128, 0)", backgroundColour)
 
-        element = self.marionette.find_element('id', "red-item")
+        element = self.marionette.find_element(By.ID, "red-item")
         backgroundColour = element.value_of_css_property("background-color")
 
         self.assertEqual("rgb(255, 0, 0)", backgroundColour)
--- a/testing/marionette/harness/marionette/tests/unit/test_screenshot.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_screenshot.py
@@ -5,16 +5,17 @@
 import base64
 import imghdr
 import struct
 import urllib
 
 from unittest import skip
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 def inline(doc, mime="text/html;charset=utf-8"):
     return "data:%s,%s" % (mime, urllib.quote(doc))
 
 
 ELEMENT = "iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAVklEQVRoge3PMQ0AMAzAsPJHVWYbjEWTj/zx7O75oXk9AAISD6QWSC2QWiC1QGqB1AKpBVILpBZILZBaILVAaoHUAqkFUgukFkgtkFogtUBqgdT6BnIBMKa1DtYxhPkAAAAASUVORK5CYII="
 HIGHLIGHTED_ELEMENT = "iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAVklEQVRoge3PQRHAQAgAMfyrwhm1sb3JIwIyN3MvmJu53f01kRqRGpEakRqRGpEakRqRGpEakRqRGpEakRqRGpEakRqRGpEakRqRGpEakRqRmvciL/gAQgW/OxTpMPwAAAAASUVORK5CYII="
@@ -140,53 +141,53 @@ class Content(ScreenCaptureTestCase):
         string = self.marionette.screenshot(full=False)
         self.assert_png(string)
         self.assertEqual(
             self.viewport_dimensions, self.get_image_dimensions(string))
 
     def test_viewport_after_scroll(self):
         self.marionette.navigate(long)
         before = self.marionette.screenshot()
-        el = self.marionette.find_element("tag name", "p")
+        el = self.marionette.find_element(By.TAG_NAME, "p")
         self.marionette.execute_script(
             "arguments[0].scrollIntoView()", script_args=[el])
         after = self.marionette.screenshot(full=False)
         self.assertNotEqual(before, after)
         self.assertGreater(self.page_y_offset, 0)
 
     def test_element(self):
         self.marionette.navigate(box)
-        el = self.marionette.find_element("tag name", "div")
+        el = self.marionette.find_element(By.TAG_NAME, "div")
         string = self.marionette.screenshot(element=el)
         self.assert_png(string)
         self.assertEqual(
             (el.rect["width"], el.rect["height"]), self.get_image_dimensions(string))
         self.assertEqual(ELEMENT, string)
 
     @skip("https://bugzilla.mozilla.org/show_bug.cgi?id=1213875")
     def test_element_scrolled_into_view(self):
         self.marionette.navigate(long)
-        el = self.marionette.find_element("tag name", "p")
+        el = self.marionette.find_element(By.TAG_NAME, "p")
         string = self.marionette.screenshot(element=el)
         self.assert_png(string)
         self.assertEqual(
             (el.rect["width"], el.rect["height"]), self.get_image_dimensions(string))
         self.assertGreater(self.page_y_offset, 0)
 
     def test_element_with_highlight(self):
         self.marionette.navigate(box)
-        el = self.marionette.find_element("tag name", "div")
+        el = self.marionette.find_element(By.TAG_NAME, "div")
         string = self.marionette.screenshot(element=el, highlights=[el])
         self.assert_png(string)
         self.assertEqual(
             (el.rect["width"], el.rect["height"]), self.get_image_dimensions(string))
         self.assertEqual(HIGHLIGHTED_ELEMENT, string)
 
     def test_binary_element(self):
         self.marionette.navigate(box)
-        el = self.marionette.find_element("tag name", "div")
+        el = self.marionette.find_element(By.TAG_NAME, "div")
         bin = self.marionette.screenshot(element=el, format="binary")
         enc = base64.b64encode(bin)
         self.assertEqual(ELEMENT, enc)
 
     def test_unknown_format(self):
         with self.assertRaises(ValueError):
             self.marionette.screenshot(format="cheese")
--- a/testing/marionette/harness/marionette/tests/unit/test_selected.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_selected.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestSelected(MarionetteTestCase):
     def test_selected(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        box = self.marionette.find_element("name", "myCheckBox")
+        box = self.marionette.find_element(By.NAME, "myCheckBox")
         self.assertFalse(box.is_selected())
         box.click()
         self.assertTrue(box.is_selected())
--- a/testing/marionette/harness/marionette/tests/unit/test_selected_chrome.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_selected_chrome.py
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 class TestSelectedChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
         self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', '_blank', 'chrome,centerscreen');")
@@ -17,12 +18,12 @@ class TestSelectedChrome(MarionetteTestC
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_selected(self):
         wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
-        box = self.marionette.find_element("id", "testBox")
+        box = self.marionette.find_element(By.ID, "testBox")
         self.assertFalse(box.is_selected())
         self.assertFalse(self.marionette.execute_script("arguments[0].checked = true;", [box]))
         self.assertTrue(box.is_selected())
--- a/testing/marionette/harness/marionette/tests/unit/test_shadow_dom.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_shadow_dom.py
@@ -1,26 +1,27 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.errors import (NoSuchElementException, StaleElementException)
+from marionette_driver.by import By
 
 
 class TestShadowDom(MarionetteTestCase):
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.enforce_gecko_prefs({"dom.webcomponents.enabled": True})
         self.marionette.navigate(self.marionette.absolute_url("test_shadow_dom.html"))
 
-        self.host = self.marionette.find_element("id", "host")
+        self.host = self.marionette.find_element(By.ID, "host")
         self.marionette.switch_to_shadow_root(self.host)
-        self.button = self.marionette.find_element("id", "button")
+        self.button = self.marionette.find_element(By.ID, "button")
 
     def test_shadow_dom(self):
         # Button in shadow root should be actionable
         self.button.click()
 
     def test_shadow_dom_after_switch_away_from_shadow_root(self):
         # Button in shadow root should be actionable
         self.button.click()
@@ -39,24 +40,24 @@ class TestShadowDom(MarionetteTestCase):
         # After removing shadow DOM host element, button should be stale
         self.assertRaises(StaleElementException, self.button.click)
 
     def test_non_existent_shadow_dom(self):
         # Jump back to top level content
         self.marionette.switch_to_shadow_root()
         # When no ShadowRoot is found, switch_to_shadow_root throws NoSuchElementException
         self.assertRaises(NoSuchElementException, self.marionette.switch_to_shadow_root,
-                          self.marionette.find_element("id", "empty-host"))
+                          self.marionette.find_element(By.ID, "empty-host"))
 
     def test_inner_shadow_dom(self):
         # Button in shadow root should be actionable
         self.button.click()
-        self.inner_host = self.marionette.find_element("id", "inner-host")
+        self.inner_host = self.marionette.find_element(By.ID, "inner-host")
         self.marionette.switch_to_shadow_root(self.inner_host)
-        self.inner_button = self.marionette.find_element("id", "inner-button")
+        self.inner_button = self.marionette.find_element(By.ID, "inner-button")
         # Nested nutton in nested shadow root should be actionable
         self.inner_button.click()
         self.marionette.switch_to_shadow_root()
         # After jumping back to parent shadow root, button should again be actionable but inner
         # button should now be stale
         self.button.click()
         self.assertRaises(StaleElementException, self.inner_button.click)
         self.marionette.switch_to_shadow_root()
--- a/testing/marionette/harness/marionette/tests/unit/test_single_finger.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_single_finger.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.marionette import Actions
 from marionette_driver.errors import MarionetteException
+from marionette_driver.by import By
 #add this directory to the path
 import os
 import sys
 sys.path.append(os.path.dirname(__file__))
 from single_finger_functions import (
         chain, chain_flick, context_menu, double_tap,
         long_press_action, long_press_on_xy_action,
         move_element, move_element_offset, press_release, single_tap, wait,
@@ -55,17 +56,17 @@ class testSingleFinger(MarionetteTestCas
     def test_long_press_on_xy_action(self):
         long_press_on_xy_action(self.marionette, self.wait_for_condition, "button1-touchstart-touchend")
 
     """
     #Skipping due to Bug 865334
     def test_long_press_fail(self):
         testAction = self.marionette.absolute_url("testAction.html")
         self.marionette.navigate(testAction)
-        button = self.marionette.find_element("id", "button1Copy")
+        button = self.marionette.find_element(By.ID, "button1Copy")
         action = Actions(self.marionette)
         action.press(button).long_press(button, 5)
         self.assertRaises(MarionetteException, action.perform)
     """
 
     def test_chain(self):
         chain(self.marionette, self.wait_for_condition, "button1-touchstart", "delayed-touchmove-touchend")
 
@@ -75,17 +76,17 @@ class testSingleFinger(MarionetteTestCas
         chain_flick(self.marionette, self.wait_for_condition, "button1-touchstart-touchmove", "buttonFlick-touchmove-touchend")
     """
 
     """
     #Skipping due to Bug 865334
     def test_touchcancel_chain(self):
         testAction = self.marionette.absolute_url("testAction.html")
         self.marionette.navigate(testAction)
-        button = self.marionette.find_element("id", "button1")
+        button = self.marionette.find_element(By.ID, "button1")
         action = Actions(self.marionette)
         action.press(button).wait(5).cancel()
         action.perform()
         expected = "button1-touchstart-touchcancel"
         self.wait_for_condition(lambda m: m.execute_script("return document.getElementById('button1').innerHTML;") == expected)
     """
 
     def test_single_tap(self):
--- a/testing/marionette/harness/marionette/tests/unit/test_single_finger_desktop.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_single_finger_desktop.py
@@ -1,10 +1,11 @@
 from marionette import MarionetteTestCase
 from marionette_driver.errors import MarionetteException
+from marionette_driver.by import By
 #add this directory to the path
 import os
 import sys
 sys.path.append(os.path.dirname(__file__))
 from single_finger_functions import (
         chain, chain_flick, context_menu, double_tap,
         long_press_action, long_press_on_xy_action,
         move_element, move_element_offset, press_release, single_tap, wait,
@@ -87,17 +88,17 @@ prefs.setIntPref("ui.click_hold_context_
         long_press_on_xy_action(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown-contextmenu-mouseup-click")
     """
     
     """
     //Skipping due to Bug 865334
     def test_long_press_fail(self):
         testAction = self.marionette.absolute_url("testAction.html")
         self.marionette.navigate(testAction)
-        button = self.marionette.find_element("id", "button1Copy")
+        button = self.marionette.find_element(By.ID, "button1Copy")
         action = Actions(self.marionette)
         action.press(button).long_press(button, 5)
         assertRaises(MarionetteException, action.perform)
     """
 
     def test_chain(self):
         chain(self.marionette, self.wait_for_condition, "button1-mousemove-mousedown", "delayed-mousemove-mouseup")
 
--- a/testing/marionette/harness/marionette/tests/unit/test_switch_frame.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_switch_frame.py
@@ -1,66 +1,67 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.by import By
 from marionette_driver.errors import (JavascriptException,
                                       NoSuchFrameException)
+from marionette_driver.by import By
 
 
 class TestSwitchFrame(MarionetteTestCase):
     def test_switch_simple(self):
         start_url = "test_iframe.html"
         verify_title = "Marionette IFrame Test"
         test_html = self.marionette.absolute_url(start_url)
         self.marionette.navigate(test_html)
         self.assertEqual(self.marionette.get_active_frame(), None)
-        frame = self.marionette.find_element("id", "test_iframe")
+        frame = self.marionette.find_element(By.ID, "test_iframe")
         self.marionette.switch_to_frame(frame)
         self.assertTrue(start_url in self.marionette.get_url())
         inner_frame_element = self.marionette.get_active_frame()
         # test that we can switch back to main frame, then switch back to the
         # inner frame with the value we got from get_active_frame
         self.marionette.switch_to_frame()
         self.assertEqual(verify_title, self.marionette.title)
         self.marionette.switch_to_frame(inner_frame_element)
         self.assertTrue(start_url in self.marionette.get_url())
 
     def test_switch_nested(self):
         start_url = "test_nested_iframe.html"
         verify_title = "Marionette IFrame Test"
         test_html = self.marionette.absolute_url(start_url)
         self.marionette.navigate(test_html)
-        frame = self.marionette.find_element("id", "test_iframe")
+        frame = self.marionette.find_element(By.ID, "test_iframe")
         self.assertEqual(self.marionette.get_active_frame(), None)
         self.marionette.switch_to_frame(frame)
         self.assertTrue(start_url in self.marionette.get_url())
         inner_frame_element = self.marionette.get_active_frame()
         # test that we can switch back to main frame, then switch back to the
         # inner frame with the value we got from get_active_frame
         self.marionette.switch_to_frame()
         self.assertEqual(verify_title, self.marionette.title)
         self.marionette.switch_to_frame(inner_frame_element)
         self.assertTrue(start_url in self.marionette.get_url())
-        inner_frame = self.marionette.find_element('id', 'inner_frame')
+        inner_frame = self.marionette.find_element(By.ID, 'inner_frame')
         self.marionette.switch_to_frame(inner_frame)
         self.assertTrue(start_url in self.marionette.get_url())
         self.marionette.switch_to_frame() # go back to main frame
         self.assertTrue(start_url in self.marionette.get_url())
         #test that we're using the right window object server-side
         self.assertTrue("test_nested_iframe.html" in self.marionette.execute_script("return window.location.href;"))
 
     def test_stack_trace(self):
         start_url = "test_iframe.html"
         verify_title = "Marionette IFrame Test"
         test_html = self.marionette.absolute_url(start_url)
         self.marionette.navigate(test_html)
-        frame = self.marionette.find_element("id", "test_iframe")
+        frame = self.marionette.find_element(By.ID, "test_iframe")
         self.assertEqual(self.marionette.get_active_frame(), None)
         self.marionette.switch_to_frame(frame)
         self.assertTrue(start_url in self.marionette.get_url())
         inner_frame_element = self.marionette.get_active_frame()
         # test that we can switch back to main frame, then switch back to the
         # inner frame with the value we got from get_active_frame
         self.marionette.switch_to_frame()
         self.assertEqual(verify_title, self.marionette.title)
@@ -71,80 +72,80 @@ class TestSwitchFrame(MarionetteTestCase
             self.marionette.execute_async_script("foo();")
         except JavascriptException as e:
             self.assertTrue("foo" in e.msg)
 
     def test_should_be_able_to_carry_on_working_if_the_frame_is_deleted_from_under_us(self):
         test_html = self.marionette.absolute_url("deletingFrame.html")
         self.marionette.navigate(test_html)
 
-        self.marionette.switch_to_frame(self.marionette.find_element('id',
+        self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
                                                                      'iframe1'))
-        killIframe = self.marionette.find_element("id", "killIframe")
+        killIframe = self.marionette.find_element(By.ID, "killIframe")
         killIframe.click()
         self.marionette.switch_to_frame()
 
-        self.assertEqual(0, len(self.marionette.find_elements("id", "iframe1")))
+        self.assertEqual(0, len(self.marionette.find_elements(By.ID, "iframe1")))
 
-        addIFrame = self.marionette.find_element("id", "addBackFrame")
+        addIFrame = self.marionette.find_element(By.ID, "addBackFrame")
         addIFrame.click()
-        self.marionette.find_element("id", "iframe1")
+        self.marionette.find_element(By.ID, "iframe1")
 
-        self.marionette.switch_to_frame(self.marionette.find_element("id",
+        self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
                                                                      "iframe1"))
 
-        self.marionette.find_element("id", "checkbox")
+        self.marionette.find_element(By.ID, "checkbox")
 
     def test_should_allow_a_user_to_switch_from_an_iframe_back_to_the_main_content_of_the_page(self):
         test_iframe = self.marionette.absolute_url("test_iframe.html")
         self.marionette.navigate(test_iframe)
         self.marionette.switch_to_frame(0)
         self.marionette.switch_to_default_content()
-        header = self.marionette.find_element("id", "iframe_page_heading")
+        header = self.marionette.find_element(By.ID, "iframe_page_heading")
         self.assertEqual(header.text, "This is the heading")
 
     def test_should_be_able_to_switch_to_a_frame_by_its_index(self):
         test_html = self.marionette.absolute_url("frameset.html")
         self.marionette.navigate(test_html)
         self.marionette.switch_to_frame(2)
-        element = self.marionette.find_element("id", "email")
+        element = self.marionette.find_element(By.ID, "email")
         self.assertEquals("email", element.get_attribute("type"))
 
     def test_should_be_able_to_switch_to_a_frame_using_a_previously_located_element(self):
         test_html = self.marionette.absolute_url("frameset.html")
         self.marionette.navigate(test_html)
-        frame = self.marionette.find_element("name", "third")
+        frame = self.marionette.find_element(By.NAME, "third")
         self.marionette.switch_to_frame(frame)
 
-        element = self.marionette.find_element("id", "email")
+        element = self.marionette.find_element(By.ID, "email")
         self.assertEquals("email", element.get_attribute("type"))
 
     def test_switch_to_frame_with_out_of_bounds_index(self):
         self.marionette.navigate(self.marionette.absolute_url("test_iframe.html"))
         count = self.marionette.execute_script("return window.frames.length;")
         self.assertRaises(NoSuchFrameException, self.marionette.switch_to_frame, count)
 
     def test_switch_to_frame_with_negative_index(self):
         self.marionette.navigate(self.marionette.absolute_url("test_iframe.html"))
         self.assertRaises(NoSuchFrameException, self.marionette.switch_to_frame, -1)
 
     def test_after_switching_to_child_frame_navigates_changes_top(self):
         frame_html = self.marionette.absolute_url("frameset.html")
         self.marionette.navigate(frame_html)
-        frame = self.marionette.find_element("name", "third")
+        frame = self.marionette.find_element(By.NAME, "third")
         self.marionette.switch_to_frame(frame)
         self.assertEqual("Unique title", self.marionette.title)
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.assertEqual("Marionette Test", self.marionette.title)
 
     def test_switch_to_parent_frame(self):
         frame_html = self.marionette.absolute_url("frameset.html")
         self.marionette.navigate(frame_html)
-        frame = self.marionette.find_element("name", "third")
+        frame = self.marionette.find_element(By.NAME, "third")
         self.marionette.switch_to_frame(frame)
 
         # If we don't find the following element we aren't on the right page
         self.marionette.find_element(By.ID, "checky")
         form_page_title = self.marionette.execute_script("return document.title")
         self.assertEqual("We Leave From Here", form_page_title)
 
         self.marionette.switch_to_parent_frame()
--- a/testing/marionette/harness/marionette/tests/unit/test_switch_remote_frame.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_switch_remote_frame.py
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 OOP_BY_DEFAULT = "dom.ipc.browser_frames.oop_by_default"
 BROWSER_FRAMES_ENABLED = "dom.mozBrowserFramesEnabled"
 
 
 class TestSwitchRemoteFrame(MarionetteTestCase):
     def setUp(self):
@@ -53,17 +54,17 @@ class TestSwitchRemoteFrame(MarionetteTe
             iframe.setAttribute('mozbrowser', true);
             iframe.setAttribute('remote', true);
             iframe.id = "remote_iframe";
             iframe.style.height = "100px";
             iframe.style.width = "100%%";
             iframe.src = "%s";
             document.body.appendChild(iframe);
             """ % self.marionette.absolute_url("test.html"))
-        remote_iframe = self.marionette.find_element("id", "remote_iframe")
+        remote_iframe = self.marionette.find_element(By.ID, "remote_iframe")
         self.marionette.switch_to_frame(remote_iframe)
         main_process = self.is_main_process
         self.assertFalse(main_process)
 
     def test_remote_frame_revisit(self):
         # test if we can revisit a remote frame (this takes a different codepath)
         self.marionette.navigate(self.marionette.absolute_url("test.html"))
         self.marionette.push_permission('browser', True)
@@ -72,25 +73,25 @@ class TestSwitchRemoteFrame(MarionetteTe
             iframe.setAttribute('mozbrowser', true);
             iframe.setAttribute('remote', true);
             iframe.id = "remote_iframe";
             iframe.style.height = "100px";
             iframe.style.width = "100%%";
             iframe.src = "%s";
             document.body.appendChild(iframe);
             """ % self.marionette.absolute_url("test.html"))
-        self.marionette.switch_to_frame(self.marionette.find_element("id",
+        self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
                                                                      "remote_iframe"))
         main_process = self.is_main_process
         self.assertFalse(main_process)
         self.marionette.switch_to_frame()
         main_process = self.is_main_process
         should_be_main_process = not self.multi_process_browser
         self.assertEqual(main_process, should_be_main_process)
-        self.marionette.switch_to_frame(self.marionette.find_element("id",
+        self.marionette.switch_to_frame(self.marionette.find_element(By.ID,
                                                                      "remote_iframe"))
         main_process = self.is_main_process
         self.assertFalse(main_process)
 
     def test_we_can_switch_to_a_remote_frame_by_index(self):
         # test if we can revisit a remote frame (this takes a different codepath)
         self.marionette.navigate(self.marionette.absolute_url("test.html"))
         self.marionette.push_permission('browser', True)
--- a/testing/marionette/harness/marionette/tests/unit/test_text.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_text.py
@@ -1,196 +1,197 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.keys import Keys
+from marionette_driver.by import By
 
 
 class TestText(MarionetteTestCase):
     def test_getText(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        l = self.marionette.find_element("id", "mozLink")
+        l = self.marionette.find_element(By.ID, "mozLink")
         self.assertEqual("Click me!", l.text)
 
     def test_clearText(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        l = self.marionette.find_element("name", "myInput")
+        l = self.marionette.find_element(By.NAME, "myInput")
         self.assertEqual("asdf", self.marionette.execute_script("return arguments[0].value;", [l]))
         l.clear()
         self.assertEqual("", self.marionette.execute_script("return arguments[0].value;", [l]))
 
     def test_sendKeys(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        l = self.marionette.find_element("name", "myInput")
+        l = self.marionette.find_element(By.NAME, "myInput")
         self.assertEqual("asdf", self.marionette.execute_script("return arguments[0].value;", [l]))
 
         # Set caret position to the middle of the input text.
         self.marionette.execute_script(
             """var el = arguments[0];
             el.selectionStart = el.selectionEnd = el.value.length / 2;""",
             script_args=[l])
 
         l.send_keys("o")
         self.assertEqual("asodf", self.marionette.execute_script("return arguments[0].value;", [l]))
 
     def test_send_keys_to_type_input(self):
         test_html = self.marionette.absolute_url("html5/test_html_inputs.html")
         self.marionette.navigate(test_html)
-        num_input = self.marionette.find_element('id', 'number')
+        num_input = self.marionette.find_element(By.ID, 'number')
         self.assertEqual("", self.marionette.execute_script("return arguments[0].value", [num_input]))
         num_input.send_keys("1234")
         self.assertEqual('1234', self.marionette.execute_script("return arguments[0].value", [num_input]))
 
     def test_should_fire_key_press_events(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys("a")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("press:" in result.text)
 
     def test_should_fire_key_down_events(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys("a")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("down:" in result.text)
 
     def test_should_fire_key_up_events(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys("a")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("up:" in result.text)
 
     def test_should_type_lowercase_characters(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys("abc def")
 
         self.assertEqual("abc def", key_reporter.get_attribute('value'))
 
     def test_should_type_uppercase_characters(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys("ABC DEF")
 
         self.assertEqual("ABC DEF", key_reporter.get_attribute('value'))
 
     def test_should_type_a_quote_characters(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys('"')
 
         self.assertEqual('"', key_reporter.get_attribute('value'))
 
     def test_should_type_an_at_character(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys('@')
 
         self.assertEqual('@', key_reporter.get_attribute('value'))
 
     def test_should_type_a_mix_of_upper_and_lower_case_character(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys('me@EXampLe.com')
 
         self.assertEqual('me@EXampLe.com', key_reporter.get_attribute('value'))
 
     def test_arrow_keys_are_not_printable(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        key_reporter = self.marionette.find_element("id", "keyReporter")
+        key_reporter = self.marionette.find_element(By.ID, "keyReporter")
         key_reporter.send_keys(Keys.ARROW_LEFT)
 
         self.assertEqual('', key_reporter.get_attribute('value'))
 
     def test_will_simulate_a_key_up_when_entering_text_into_input_elements(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyUp")
+        element = self.marionette.find_element(By.ID, "keyUp")
         element.send_keys("I like cheese")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertEqual(result.text, "I like cheese")
 
     def test_will_simulate_a_key_down_when_entering_text_into_input_elements(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyDown")
+        element = self.marionette.find_element(By.ID, "keyDown")
         element.send_keys("I like cheese")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         # Because the key down gets the result before the input element is
         # filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def test_will_simulate_a_key_press_when_entering_text_into_input_elements(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyPress")
+        element = self.marionette.find_element(By.ID, "keyPress")
         element.send_keys("I like cheese")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         # Because the key down gets the result before the input element is
         # filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def test_will_simulate_a_keyup_when_entering_text_into_textareas(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyUpArea")
+        element = self.marionette.find_element(By.ID, "keyUpArea")
         element.send_keys("I like cheese")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertEqual(result.text, "I like cheese")
 
     def test_will_simulate_a_keydown_when_entering_text_into_textareas(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyDownArea")
+        element = self.marionette.find_element(By.ID, "keyDownArea")
         element.send_keys("I like cheese")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         # Because the key down gets the result before the input element is
         # filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def test_will_simulate_a_keypress_when_entering_text_into_textareas(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyPressArea")
+        element = self.marionette.find_element(By.ID, "keyPressArea")
         element.send_keys("I like cheese")
 
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         # Because the key down gets the result before the input element is
         # filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def test_should_report_key_code_of_arrow_keys_up_down_events(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        result = self.marionette.find_element("id", "result")
-        element = self.marionette.find_element("id", "keyReporter")
+        result = self.marionette.find_element(By.ID, "result")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         element.send_keys(Keys.ARROW_DOWN)
         self.assertTrue("down: 40" in result.text.strip())
         self.assertTrue("up: 40" in result.text.strip())
 
         element.send_keys(Keys.ARROW_UP)
         self.assertTrue("down: 38" in result.text.strip())
         self.assertTrue("up: 38" in result.text.strip())
 
@@ -203,19 +204,19 @@ class TestText(MarionetteTestCase):
         self.assertTrue("up: 39" in result.text.strip())
 
         #  And leave no rubbish/printable keys in the "keyReporter"
         self.assertEqual(element.get_attribute("value"), "")
 
     def testNumericNonShiftKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyReporter")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         numericLineCharsNonShifted = "`1234567890-=[]\\,.'/42"
         element.send_keys(numericLineCharsNonShifted)
         self.assertEqual(element.get_attribute("value"), numericLineCharsNonShifted)
 
     def testShouldTypeAnInteger(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element("id", "keyReporter")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         element.send_keys(1234)
         self.assertEqual(element.get_attribute("value"), "1234")
--- a/testing/marionette/harness/marionette/tests/unit/test_text_chrome.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_text_chrome.py
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
 
 
 ''' Disabled in bug 896043 and when working on Chrome code re-enable for bug 896046
 class TestTextChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
         self.win = self.marionette.current_window_handle
@@ -21,31 +22,31 @@ class TestTextChrome(MarionetteTestCase)
         self.marionette.switch_to_window(self.win)
         MarionetteTestCase.tearDown(self)
 
     def test_getText(self):
         wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
-        box = self.marionette.find_element("id", "textInput")
+        box = self.marionette.find_element(By.ID, "textInput")
         self.assertEqual("test", box.text)
 
     def test_clearText(self):
         wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
-        box = self.marionette.find_element("id", "textInput")
+        box = self.marionette.find_element(By.ID, "textInput")
         self.assertEqual("test", box.text)
         box.clear()
         self.assertEqual("", box.text)
 
     def test_sendKeys(self):
         wins = self.marionette.window_handles
         wins.remove(self.win)
         newWin = wins.pop()
         self.marionette.switch_to_window(newWin)
-        box = self.marionette.find_element("id", "textInput")
+        box = self.marionette.find_element(By.ID, "textInput")
         self.assertEqual("test", box.text)
         box.send_keys("at")
         self.assertEqual("attest", box.text)
 '''
\ No newline at end of file
--- a/testing/marionette/harness/marionette/tests/unit/test_timeouts.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_timeouts.py
@@ -2,16 +2,18 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.marionette import HTMLElement
 from marionette_driver.errors import (NoSuchElementException,
                                       MarionetteException,
                                       ScriptTimeoutException)
+from marionette_driver.by import By
+
 
 class TestTimeouts(MarionetteTestCase):
     def test_pagetimeout_notdefinetimeout_pass(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
 
     def test_pagetimeout_fail(self):
         self.marionette.timeouts("page load", 0)
@@ -22,34 +24,34 @@ class TestTimeouts(MarionetteTestCase):
         self.marionette.timeouts("page load", 60000)
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
 
     def test_searchtimeout_notfound_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.marionette.timeouts("implicit", 1000)
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "I'm not on the page")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
         self.marionette.timeouts("implicit", 0)
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "I'm not on the page")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "I'm not on the page")
 
     def test_searchtimeout_found_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        button = self.marionette.find_element("id", "createDivButton")
+        button = self.marionette.find_element(By.ID, "createDivButton")
         button.click()
         self.marionette.timeouts("implicit", 8000)
-        self.assertEqual(HTMLElement, type(self.marionette.find_element("id", "newDiv")))
+        self.assertEqual(HTMLElement, type(self.marionette.find_element(By.ID, "newDiv")))
 
     def test_searchtimeout_found(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
-        button = self.marionette.find_element("id", "createDivButton")
+        button = self.marionette.find_element(By.ID, "createDivButton")
         button.click()
-        self.assertRaises(NoSuchElementException, self.marionette.find_element, "id", "newDiv")
+        self.assertRaises(NoSuchElementException, self.marionette.find_element, By.ID, "newDiv")
 
     def test_execute_async_timeout_settimeout(self):
         test_html = self.marionette.absolute_url("test.html")
         self.marionette.navigate(test_html)
         self.marionette.timeouts("script", 10000)
         self.assertRaises(ScriptTimeoutException, self.marionette.execute_async_script, "var x = 1;")
 
     def test_no_timeout_settimeout(self):
--- a/testing/marionette/harness/marionette/tests/unit/test_typing.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_typing.py
@@ -2,196 +2,197 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import urllib
 
 from marionette.marionette_test import MarionetteTestCase, skip_if_b2g
 from marionette_driver.keys import Keys
 from marionette_driver.errors import ElementNotVisibleException
+from marionette_driver.by import By
 
 
 def inline(doc):
     return "data:text/html;charset=utf-8,%s" % urllib.quote(doc)
 
 
 class TestTyping(MarionetteTestCase):
     def testShouldFireKeyPressEvents(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("a")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("press:" in result.text)
 
     def testShouldFireKeyDownEvents(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("I")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("down" in result.text)
 
     def testShouldFireKeyUpEvents(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("a")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertTrue("up:" in result.text)
 
     def testShouldTypeLowerCaseLetters(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("abc def")
         self.assertEqual(keyReporter.get_attribute("value"), "abc def")
 
     def testShouldBeAbleToTypeCapitalLetters(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("ABC DEF")
         self.assertEqual(keyReporter.get_attribute("value"), "ABC DEF")
 
     @skip_if_b2g
     def testCutAndPasteShortcuts(self):
         # Test that modifier keys work via copy/paste shortcuts.
         if self.marionette.session_capabilities['platformName'] == 'Darwin':
             mod_key = Keys.META
         else:
             mod_key = Keys.CONTROL
 
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         self.assertEqual(keyReporter.get_attribute("value"), "")
         keyReporter.send_keys("zyxwvutsr")
         self.assertEqual(keyReporter.get_attribute("value"), "zyxwvutsr")
 
         # Select all and cut.
         keyReporter.send_keys(mod_key, 'a')
         keyReporter.send_keys(mod_key, 'x')
         self.assertEqual(keyReporter.get_attribute("value"), "")
 
         self.marionette.set_context("chrome")
-        url_bar = self.marionette.find_element("id", "urlbar")
+        url_bar = self.marionette.find_element(By.ID, "urlbar")
 
         # Clear and paste.
         url_bar.send_keys(mod_key, 'a')
         url_bar.send_keys(Keys.BACK_SPACE)
 
         self.assertEqual(url_bar.get_attribute("value"), "")
         url_bar.send_keys(mod_key, 'v')
         self.assertEqual(url_bar.get_attribute("value"), "zyxwvutsr")
 
     def testShouldBeAbleToTypeQuoteMarks(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("\"")
         self.assertEqual(keyReporter.get_attribute("value"), "\"")
 
     def testShouldBeAbleToTypeTheAtCharacter(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("@")
         self.assertEqual(keyReporter.get_attribute("value"), "@")
 
     def testShouldBeAbleToMixUpperAndLowerCaseLetters(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys("me@eXample.com")
         self.assertEqual(keyReporter.get_attribute("value"), "me@eXample.com")
 
     def testArrowKeysShouldNotBePrintable(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        keyReporter = self.marionette.find_element("id", "keyReporter")
+        keyReporter = self.marionette.find_element(By.ID, "keyReporter")
         keyReporter.send_keys(Keys.ARROW_LEFT)
         self.assertEqual(keyReporter.get_attribute("value"), "")
 
     def testWillSimulateAKeyUpWhenEnteringTextIntoInputElements(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyUp")
+        element = self.marionette.find_element(By.ID, "keyUp")
         element.send_keys("I like cheese")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertEqual(result.text, "I like cheese")
 
     def testWillSimulateAKeyDownWhenEnteringTextIntoInputElements(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyDown")
+        element = self.marionette.find_element(By.ID, "keyDown")
         element.send_keys("I like cheese")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         #  Because the key down gets the result before the input element is
         #  filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def testWillSimulateAKeyPressWhenEnteringTextIntoInputElements(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyPress")
+        element = self.marionette.find_element(By.ID, "keyPress")
         element.send_keys("I like cheese")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         #  Because the key down gets the result before the input element is
         #  filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def testWillSimulateAKeyUpWhenEnteringTextIntoTextAreas(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyUpArea")
+        element = self.marionette.find_element(By.ID, "keyUpArea")
         element.send_keys("I like cheese")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         self.assertEqual(result.text, "I like cheese")
 
     def testWillSimulateAKeyDownWhenEnteringTextIntoTextAreas(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyDownArea")
+        element = self.marionette.find_element(By.ID, "keyDownArea")
         element.send_keys("I like cheese")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         #  Because the key down gets the result before the input element is
         #  filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def testWillSimulateAKeyPressWhenEnteringTextIntoTextAreas(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyPressArea")
+        element = self.marionette.find_element(By.ID, "keyPressArea")
         element.send_keys("I like cheese")
-        result = self.marionette.find_element("id", "result")
+        result = self.marionette.find_element(By.ID, "result")
         #  Because the key down gets the result before the input element is
         #  filled, we're a letter short here
         self.assertEqual(result.text, "I like chees")
 
     def testShouldReportKeyCodeOfArrowKeysUpDownEvents(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        result = self.marionette.find_element("id", "result")
-        element = self.marionette.find_element("id", "keyReporter")
+        result = self.marionette.find_element(By.ID, "result")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         element.send_keys(Keys.ARROW_DOWN)
         self.assertTrue("down: 40" in result.text.strip())
         self.assertTrue("up: 40" in result.text.strip())
 
         element.send_keys(Keys.ARROW_UP)
         self.assertTrue("down: 38" in  result.text.strip())
         self.assertTrue("up: 38" in result.text.strip())
 
@@ -206,96 +207,96 @@ class TestTyping(MarionetteTestCase):
         #  And leave no rubbish/printable keys in the "keyReporter"
         self.assertEqual(element.get_attribute("value"), "")
 
     ''' Disabled. Reenable in Bug 1068728
     def testNumericShiftKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        result = self.marionette.find_element("id", "result")
-        element = self.marionette.find_element("id", "keyReporter")
+        result = self.marionette.find_element(By.ID, "result")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         numericShiftsEtc = "~!@#$%^&*()_+{}:i\"<>?|END~"
         element.send_keys(numericShiftsEtc)
         self.assertEqual(element.get_attribute("value"), numericShiftsEtc)
         self.assertTrue(" up: 16" in result.text.strip())
     '''
 
     def testLowerCaseAlphaKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyReporter")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         lowerAlphas = "abcdefghijklmnopqrstuvwxyz"
         element.send_keys(lowerAlphas)
         self.assertEqual(element.get_attribute("value"), lowerAlphas)
 
     ''' Disabled. Reenable in Bug 1068735
     def testUppercaseAlphaKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        result = self.marionette.find_element("id", "result")
-        element = self.marionette.find_element("id", "keyReporter")
+        result = self.marionette.find_element(By.ID, "result")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         upperAlphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         element.send_keys(upperAlphas)
         self.assertEqual(element.get_attribute("value"), upperAlphas)
         self.assertTrue(" up: 16" in result.text.strip())
     '''
 
     ''' Disabled. Reenable in Bug 1068726
     def testAllPrintableKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        result = self.marionette.find_element("id", "result")
-        element = self.marionette.find_element("id", "keyReporter")
+        result = self.marionette.find_element(By.ID, "result")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         allPrintable = "!\"#$%&'()*+,-./0123456789:<=>?@ ABCDEFGHIJKLMNOPQRSTUVWXYZ [\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
         element.send_keys(allPrintable)
 
         self.assertTrue(element.get_attribute("value"), allPrintable)
         self.assertTrue(" up: 16" in result.text.strip())
     '''
 
     ''' Disabled. Reenable in Bug 1068733
     def testSpecialSpaceKeys(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyReporter")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         element.send_keys("abcd" + Keys.SPACE + "fgh" + Keys.SPACE + "ij")
         self.assertEqual(element.get_attribute("value"), "abcd fgh ij")
     '''
 
     def testShouldTypeAnInteger(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        element = self.marionette.find_element("id", "keyReporter")
+        element = self.marionette.find_element(By.ID, "keyReporter")
         element.send_keys(1234)
         self.assertEqual(element.get_attribute("value"), "1234")
 
     def testShouldSendKeysToElementsWithoutTheValueAttribute(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
         # If we don't get an error below we are good
-        self.marionette.find_element('tag name', 'body').send_keys('foo')
+        self.marionette.find_element(By.TAG_NAME, 'body').send_keys('foo')
 
     def testShouldThrowElementNotVisibleWhenInputHidden(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        not_displayed = self.marionette.find_element('id', 'notDisplayed')
+        not_displayed = self.marionette.find_element(By.ID, 'notDisplayed')
         self.assertRaises(ElementNotVisibleException, not_displayed.send_keys, 'foo')
 
     def test_appends_to_input_text(self):
         self.marionette.navigate(inline("<input>"))
-        el = self.marionette.find_element("tag name", "input")
+        el = self.marionette.find_element(By.TAG_NAME, "input")
         el.send_keys("foo")
         el.send_keys("bar")
         self.assertEqual("foobar", el.get_attribute("value"))
 
     def test_appends_to_textarea(self):
         self.marionette.navigate(inline("<textarea></textarea>"))
-        textarea = self.marionette.find_element("tag name", "textarea")
+        textarea = self.marionette.find_element(By.TAG_NAME, "textarea")
         textarea.send_keys("foo")
         textarea.send_keys("bar")
         self.assertEqual("foobar", textarea.get_attribute("value"))
--- a/testing/marionette/harness/marionette/tests/unit/test_visibility.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_visibility.py
@@ -1,114 +1,116 @@
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
+
 
 class TestVisibility(MarionetteTestCase):
 
     def testShouldAllowTheUserToTellIfAnElementIsDisplayedOrNot(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        self.assertTrue(self.marionette.find_element('id', "displayed").is_displayed())
-        self.assertFalse(self.marionette.find_element('id', "none").is_displayed())
-        self.assertFalse(self.marionette.find_element('id',
+        self.assertTrue(self.marionette.find_element(By.ID, "displayed").is_displayed())
+        self.assertFalse(self.marionette.find_element(By.ID, "none").is_displayed())
+        self.assertFalse(self.marionette.find_element(By.ID,
             "suppressedParagraph").is_displayed())
-        self.assertFalse(self.marionette.find_element('id', "hidden").is_displayed())
+        self.assertFalse(self.marionette.find_element(By.ID, "hidden").is_displayed())
 
     def testVisibilityShouldTakeIntoAccountParentVisibility(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        childDiv = self.marionette.find_element('id', "hiddenchild")
-        hiddenLink = self.marionette.find_element('id', "hiddenlink")
+        childDiv = self.marionette.find_element(By.ID, "hiddenchild")
+        hiddenLink = self.marionette.find_element(By.ID, "hiddenlink")
 
         self.assertFalse(childDiv.is_displayed())
         self.assertFalse(hiddenLink.is_displayed())
 
     def testShouldCountElementsAsVisibleIfStylePropertyHasBeenSet(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        shown = self.marionette.find_element('id', "visibleSubElement")
+        shown = self.marionette.find_element(By.ID, "visibleSubElement")
         self.assertTrue(shown.is_displayed())
 
     def testShouldModifyTheVisibilityOfAnElementDynamically(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
-        element = self.marionette.find_element('id', "hideMe")
+        element = self.marionette.find_element(By.ID, "hideMe")
         self.assertTrue(element.is_displayed())
         element.click()
         self.assertFalse(element.is_displayed())
 
     def testHiddenInputElementsAreNeverVisible(self):
         test_html = self.marionette.absolute_url("javascriptPage.html")
         self.marionette.navigate(test_html)
 
-        shown = self.marionette.find_element('name', "hidden")
+        shown = self.marionette.find_element(By.NAME, "hidden")
 
         self.assertFalse(shown.is_displayed())
 
     def testShouldSayElementsWithNegativeTransformAreNotDisplayed(self):
         test_html = self.marionette.absolute_url("cssTransform.html")
         self.marionette.navigate(test_html)
 
-        elementX = self.marionette.find_element("id", 'parentX')
+        elementX = self.marionette.find_element(By.ID, 'parentX')
         self.assertFalse(elementX.is_displayed())
-        elementY = self.marionette.find_element("id", 'parentY')
+        elementY = self.marionette.find_element(By.ID, 'parentY')
         self.assertFalse(elementY.is_displayed())
 
     def testShouldSayElementsWithParentWithNegativeTransformAreNotDisplayed(self):
         test_html = self.marionette.absolute_url("cssTransform.html")
         self.marionette.navigate(test_html)
 
-        elementX = self.marionette.find_element("id", 'childX')
+        elementX = self.marionette.find_element(By.ID, 'childX')
         self.assertFalse(elementX.is_displayed())
-        elementY = self.marionette.find_element("id", 'childY')
+        elementY = self.marionette.find_element(By.ID, 'childY')
         self.assertFalse(elementY.is_displayed())
 
     def testShouldSayElementWithZeroTransformIsVisible(self):
         test_html = self.marionette.absolute_url("cssTransform.html")
         self.marionette.navigate(test_html)
 
-        zero_tranform = self.marionette.find_element("id", 'zero-tranform')
+        zero_tranform = self.marionette.find_element(By.ID, 'zero-tranform')
         self.assertTrue(zero_tranform.is_displayed())
 
     def testShouldSayElementIsVisibleWhenItHasNegativeTransformButElementisntInANegativeSpace(self):
         test_html = self.marionette.absolute_url("cssTransform2.html")
         self.marionette.navigate(test_html)
-        negative_percent__tranform = self.marionette.find_element("id", 'negative-percentage-transformY')
+        negative_percent__tranform = self.marionette.find_element(By.ID, 'negative-percentage-transformY')
         self.assertTrue(negative_percent__tranform.is_displayed())
 
     def testShouldSayElementIsInvisibleWhenOverflowXIsHiddenAndOutOfViewport(self):
         test_html = self.marionette.absolute_url("bug814037.html")
         self.marionette.navigate(test_html)
-        overflow_x = self.marionette.find_element("id", "assertMe2")
+        overflow_x = self.marionette.find_element(By.ID, "assertMe2")
         self.assertFalse(overflow_x.is_displayed())
 
     def testShouldShowElementNotVisibleWithHiddenAttribute(self):
         test_html = self.marionette.absolute_url("hidden.html")
         self.marionette.navigate(test_html)
-        singleHidden = self.marionette.find_element('id', 'singleHidden')
+        singleHidden = self.marionette.find_element(By.ID, 'singleHidden')
         self.assertFalse(singleHidden.is_displayed())
 
     def testShouldShowElementNotVisibleWhenParentElementHasHiddenAttribute(self):
         test_html = self.marionette.absolute_url("hidden.html")
         self.marionette.navigate(test_html)
-        child = self.marionette.find_element('id', 'child')
+        child = self.marionette.find_element(By.ID, 'child')
         self.assertFalse(child.is_displayed())
 
     def testShouldClickOnELementPartiallyOffLeft(self):
         test_html = self.marionette.absolute_url("element_left.html")
         self.marionette.navigate(test_html)
-        self.marionette.find_element('css selector', '.element').click()
+        self.marionette.find_element(By.CSS_SELECTOR, '.element').click()
 
     def testShouldClickOnELementPartiallyOffRight(self):
         test_html = self.marionette.absolute_url("element_right.html")
         self.marionette.navigate(test_html)
-        self.marionette.find_element('css selector', '.element').click()
+        self.marionette.find_element(By.CSS_SELECTOR, '.element').click()
 
     def testShouldClickOnELementPartiallyOffTop(self):
         test_html = self.marionette.absolute_url("element_top.html")
         self.marionette.navigate(test_html)
-        self.marionette.find_element('css selector', '.element').click()
+        self.marionette.find_element(By.CSS_SELECTOR, '.element').click()
 
     def testShouldClickOnELementPartiallyOffBottom(self):
         test_html = self.marionette.absolute_url("element_bottom.html")
         self.marionette.navigate(test_html)
-        self.marionette.find_element('css selector', '.element').click()
+        self.marionette.find_element(By.CSS_SELECTOR, '.element').click()
--- a/testing/marionette/harness/marionette/tests/unit/test_window_handles.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_window_handles.py
@@ -1,31 +1,32 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from marionette import MarionetteTestCase
 from marionette_driver.keys import Keys
+from marionette_driver.by import By
 
 
 class TestWindowHandles(MarionetteTestCase):
 
     def test_new_tab_window_handles(self):
 
         keys = []
         if self.marionette.session_capabilities['platformName'] == 'Darwin':
             keys.append(Keys.META)
         else:
             keys.append(Keys.CONTROL)
         keys.append('t')
 
         origin_win = self.marionette.current_window_handle
 
         with self.marionette.using_context("chrome"):
-            main_win = self.marionette.find_element("id", "main-window")
+            main_win = self.marionette.find_element(By.ID, "main-window")
             main_win.send_keys(*keys)
 
         self.wait_for_condition(lambda mn: len(mn.window_handles) == 2)
         handles = self.marionette.window_handles
         handles.remove(origin_win)
         new_tab = handles.pop()
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.get_url(), "about:newtab")
@@ -33,17 +34,17 @@ class TestWindowHandles(MarionetteTestCa
 
         self.marionette.switch_to_window(origin_win)
         self.assertEqual(self.marionette.get_url(), "about:blank")
 
     def test_link_opened_tab_window_handles(self):
         tab_testpage = self.marionette.absolute_url("windowHandles.html")
         self.marionette.navigate(tab_testpage)
         start_win = self.marionette.current_window_handle
-        link = self.marionette.find_element("id", "new-tab")
+        link = self.marionette.find_element(By.ID, "new-tab")
         link.click()
         self.wait_for_condition(lambda mn: len(mn.window_handles) == 2)
 
         handles = self.marionette.window_handles
         handles.remove(start_win)
         dest_win = handles.pop()
 
         self.marionette.switch_to_window(dest_win)
@@ -62,27 +63,27 @@ class TestWindowHandles(MarionetteTestCa
     def test_chrome_windows(self):
         opener_page = self.marionette.absolute_url("windowHandles.html")
 
         self.marionette.navigate(opener_page)
 
         # Window handles don't persist in cases of remoteness change.
         start_tab = self.marionette.current_window_handle
 
-        self.marionette.find_element("id", "new-window").click()
+        self.marionette.find_element(By.ID, "new-window").click()
 
         self.assertEqual(len(self.marionette.window_handles), 2)
         self.assertEqual(len(self.marionette.chrome_window_handles), 2)
         windows = self.marionette.window_handles
         windows.remove(start_tab)
         dest_tab = windows.pop()
         self.marionette.switch_to_window(dest_tab)
 
         self.marionette.navigate(opener_page)
-        new_tab_link = self.marionette.find_element("id", "new-tab")
+        new_tab_link = self.marionette.find_element(By.ID, "new-tab")
 
         for i in range(3):
             new_tab_link.click()
             self.marionette.switch_to_window(dest_tab)
             self.wait_for_condition(lambda mn: len(mn.window_handles) == i + 3)
             self.assertEqual(len(self.marionette.chrome_window_handles), 2)
 
         self.marionette.close_chrome_window()
@@ -93,34 +94,34 @@ class TestWindowHandles(MarionetteTestCa
     def test_tab_and_window_handles(self):
         start_tab = self.marionette.current_window_handle
         start_chrome_window = self.marionette.current_chrome_window_handle
         tab_open_page = self.marionette.absolute_url("windowHandles.html")
         window_open_page = self.marionette.absolute_url("test_windows.html")
 
         # Open a new tab and switch to it.
         self.marionette.navigate(tab_open_page)
-        link = self.marionette.find_element("id", "new-tab")
+        link = self.marionette.find_element(By.ID, "new-tab")
         link.click()
 
         self.wait_for_condition(lambda mn: len(mn.window_handles) == 2)
         self.assertEqual(len(self.marionette.chrome_window_handles), 1)
         self.assertEqual(self.marionette.current_chrome_window_handle, start_chrome_window)
 
         handles = self.marionette.window_handles
         handles.remove(start_tab)
 
         new_tab = handles.pop()
         self.marionette.switch_to_window(new_tab)
         self.assertEqual(self.marionette.get_url(), "about:blank")
 
         # Open a new window from the new tab.
         self.marionette.navigate(window_open_page)
 
-        link = self.marionette.find_element("link text", "Open new window")
+        link = self.marionette.find_element(By.LINK_TEXT, "Open new window")
         link.click()
         self.wait_for_condition(lambda mn: len(mn.window_handles) == 3)
 
         self.assertEqual(len(self.marionette.chrome_window_handles), 2)
         self.assertEqual(self.marionette.current_chrome_window_handle, start_chrome_window)
 
         # Find the new window and switch to it.
         handles = self.marionette.window_handles
--- a/testing/marionette/harness/marionette/tests/unit/test_window_management.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_window_management.py
@@ -1,14 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import time
 from marionette import MarionetteTestCase
+from marionette_driver.by import By
+
 
 class TestSwitchWindow(MarionetteTestCase):
     def open_new_window(self):
         self.marionette.set_context("chrome")
         self.marionette.set_script_timeout(5000)
         self.marionette.execute_async_script("""
 var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
                    .getService(Components.interfaces.nsIWindowWatcher);
@@ -55,17 +57,17 @@ if (win != null)
         self.assertEqual(self.marionette.current_window_handle, orig_win)
         self.assertEqual(len(self.marionette.window_handles), len(orig_available))
 
     def testShouldLoadAWindowAndThenCloseIt(self):
         test_html = self.marionette.absolute_url("test_windows.html")
         self.marionette.navigate(test_html)
         current = self.marionette.current_window_handle
 
-        self.marionette.find_element('link text', "Open new window").click()
+        self.marionette.find_element(By.LINK_TEXT, "Open new window").click()
         count = 0
         while True:
             window_handles = self.marionette.window_handles
             window_handles.remove(current)
             if len(window_handles) > 0:
                 break
             elif count > 10:
                 self.fail("There were no windows that appeared when we clicked earlier")
@@ -86,17 +88,17 @@ if (win != null)
         self.marionette.switch_to_window(current)
         self.assertEqual(1, len(self.marionette.window_handles))
 
     def testShouldCauseAWindowToLoadAndCheckItIsOpenThenCloseIt(self):
         test_html = self.marionette.absolute_url("test_windows.html")
         self.marionette.navigate(test_html)
         current = self.marionette.current_window_handle
 
-        self.marionette.find_element('link text',"Open new window").click()
+        self.marionette.find_element(By.LINK_TEXT,"Open new window").click()
         all_handles = self.marionette.window_handles
         self.assertEqual(2, len(all_handles))
         self.marionette.switch_to_window([x for x in all_handles if x != current][0])
 
         # Let's close and check
         self.marionette.close()
         self.marionette.switch_to_window(current)
         self.assertEqual(1, len(self.marionette.window_handles))
--- a/testing/marionette/harness/marionette/tests/unit/test_window_switching.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_window_switching.py
@@ -10,17 +10,17 @@ from marionette_driver.wait import Wait
 
 
 class TestWindowSwitching(MarionetteTestCase):
     def testJSWindowCreationAndSwitching(self):
         test_html = self.marionette.absolute_url("test_windows.html")
         self.marionette.navigate(test_html)
 
         self.current_window = self.marionette.current_window_handle
-        link = self.marionette.find_element("link text", "Open new window")
+        link = self.marionette.find_element(By.LINK_TEXT, "Open new window")
         link.click()
 
         windows = self.marionette.window_handles
         windows.remove(self.current_window)
         self.marionette.switch_to_window(windows[0])
 
         title = self.marionette.execute_script("return document.title")
         results_page = self.marionette.absolute_url("resultPage.html")