Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions appium/webdriver/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from selenium.webdriver.common.by import By
from selenium.webdriver.common.utils import keys_to_typing
from selenium.webdriver.remote.command import Command as RemoteCommand

from .extensions.search_context import AppiumWebElementSearchContext
Expand Down Expand Up @@ -204,3 +205,18 @@ def set_value(self, value):
}
self._execute(Command.SET_IMMEDIATE_VALUE, data)
return self

# Override
def send_keys(self, *value):
"""Simulates typing into the element.

Args:
value (str): A string for typing.

Returns:
`appium.webdriver.webelement.WebElement`
"""
_value = keys_to_typing(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about _value -> keys?

self._execute(RemoteCommand.SEND_KEYS_TO_ELEMENT,
{'text': "".join(_value), 'value': _value})
return self
61 changes: 61 additions & 0 deletions test/unit/webdriver/webelement_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

import json
import tempfile

import httpretty

from appium.webdriver.webelement import WebElement as MobileWebElement
from test.unit.helper.test_helper import (
android_w3c_driver,
appium_command,
get_httpretty_request_body
)


class TestWebElement(object):

@httpretty.activate
def test_send_key(self):
driver = android_w3c_driver()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element/element_id/value')
)

element = MobileWebElement(driver, 'element_id', w3c=True)
element.send_keys('happy testing')

d = get_httpretty_request_body(httpretty.last_request())
assert d['text'] == ''.join(d['value'])

@httpretty.activate
def test_send_key_with_file(self):
driver = android_w3c_driver()
# Should not send this file
tmp_f = tempfile.NamedTemporaryFile()
httpretty.register_uri(
httpretty.POST,
appium_command('/session/1234567890/element/element_id/value')
)

try:
element = MobileWebElement(driver, 'element_id', w3c=True)
element.send_keys(tmp_f.name)
finally:
tmp_f.close()

d = get_httpretty_request_body(httpretty.last_request())
assert d['text'] == ''.join(d['value'])