Skip to content

Commit

Permalink
ActionsChains.send_keys should use <session>/keys endpoint
Browse files Browse the repository at this point in the history
added test, unignoring some tests that run just fine on mac + firefox
(even without native events)
Fixes Issue SeleniumHQ#6348
  • Loading branch information
lukeis committed Oct 22, 2013
1 parent 4ae0b52 commit f2ed578
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
46 changes: 19 additions & 27 deletions py/selenium/webdriver/common/action_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,10 @@ def key_down(self, value, element=None):
- element: The element to send keys.
If None, sends a key to current focused element.
"""
typing = []
for val in value:
if isinstance(val, Keys):
typing.append(val)
elif isinstance(val, int):
val = str(val)
for i in range(len(val)):
typing.append(val[i])
else:
for i in range(len(val)):
typing.append(val[i])

if element: self.click(element)
self._actions.append(lambda:
self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {
"value": typing }))
"value": self._keys_to_typing(value) }))
return self

def key_up(self, value, element=None):
Expand All @@ -160,22 +148,10 @@ def key_up(self, value, element=None):
- element: The element to send keys.
If None, sends a key to current focused element.
"""
typing = []
for val in value:
if isinstance(val, Keys):
typing.append(val)
elif isinstance(val, int):
val = str(val)
for i in range(len(val)):
typing.append(val[i])
else:
for i in range(len(val)):
typing.append(val[i])

if element: self.click(element)
self._actions.append(lambda:
self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT, {
"value": typing }))
"value": self._keys_to_typing(value) }))
return self

def move_by_offset(self, xoffset, yoffset):
Expand Down Expand Up @@ -241,7 +217,8 @@ def send_keys(self, *keys_to_send):
- keys_to_send: The keys to send.
"""
self._actions.append(lambda:
self._driver.switch_to_active_element().send_keys(*keys_to_send))
self._driver.execute(Command.SEND_KEYS_TO_ACTIVE_ELEMENT,
{ 'value': self._keys_to_typing(keys_to_send)}))
return self

def send_keys_to_element(self, element, *keys_to_send):
Expand All @@ -255,3 +232,18 @@ def send_keys_to_element(self, element, *keys_to_send):
self._actions.append(lambda:
element.send_keys(*keys_to_send))
return self

def _keys_to_typing(self, value):
typing = []
for val in value:
if isinstance(val, Keys):
typing.append(val)
elif isinstance(val, int):
val = str(val)
for i in range(len(val)):
typing.append(val[i])
else:
for i in range(len(val)):
typing.append(val[i])
return typing

24 changes: 22 additions & 2 deletions py/test/selenium/webdriver/common/interactions_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
"""Tests for advanced user interactions."""
import unittest
import pytest
import sys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait

@pytest.mark.skipif('sys.platform == "darwin"')
class AdvancedUserInteractionTest(unittest.TestCase):
def _before(self):
if self.driver.capabilities['browserName'] == 'firefox' and sys.platform == 'darwin':
pytest.skip("native events not supported on Mac for Firefox")

def performDragAndDropWithMouse(self):
"""Copied from org.openqa.selenium.interactions.TestBasicMouseInterface."""
#self._before()
self._loadPage("draggableLists")
dragReporter = self.driver.find_element_by_id("dragging_reports")
toDrag = self.driver.find_element_by_id("rightitem-3")
Expand Down Expand Up @@ -96,7 +101,7 @@ def testDragAndDrop(self):

def testDoubleClick(self):
"""Copied from org.openqa.selenium.interactions.TestBasicMouseInterface."""
pytest.skip("doubleClick is failing server-side")
#pytest.skip("doubleClick is failing server-side")
self._loadPage("javascriptPage")
toDoubleClick = self.driver.find_element_by_id("doubleClickField")

Expand Down Expand Up @@ -189,6 +194,7 @@ def testSelectingMultipleItems(self):

@pytest.mark.ignore_chrome
def testMovingMouseBackAndForthPastViewPort(self):
self._before()
self._loadPage("veryLargeCanvas")

firstTarget = self.driver.find_element_by_id("r1")
Expand Down Expand Up @@ -226,6 +232,20 @@ def testMovingMouseBackAndForthPastViewPort(self):
.perform()
expectedEvents += " Fourth"
wait.until(expectedEventsFired)

def testSendingKeysToActiveElementWithModifier(self):
self._loadPage("formPage")
e = self.driver.find_element_by_id("working")
e.click()

ActionChains(self.driver) \
.key_down(Keys.SHIFT) \
.send_keys("abc")\
.key_up(Keys.SHIFT)\
.perform()

self.assertEqual("ABC", e.get_attribute('value'))


def _pageURL(self, name):
return "http://localhost:%d/%s.html" % (self.webserver.port, name)
Expand Down

0 comments on commit f2ed578

Please sign in to comment.