diff --git a/javascript/atoms/events.js b/javascript/atoms/events.js index 251e34d53259c..f29e9e5c1c77e 100644 --- a/javascript/atoms/events.js +++ b/javascript/atoms/events.js @@ -523,7 +523,8 @@ bot.events.TouchEventFactory_.prototype.create = function (target, opt_args) { } else if (strategy == bot.events.TouchEventStrategy_.INIT_TOUCH_EVENT) { event = doc.createEvent('TouchEvent'); // Different browsers have different implementations of initTouchEvent. - if (event.initTouchEvent.length == 0) { + // if (event.initTouchEvent.length == 0) { + if (!goog.userAgent.product.IOS) { // Chrome/Android. event.initTouchEvent(touches, targetTouches, changedTouches, this.type_, view, /*screenX*/ 0, /*screenY*/ 0, args.clientX, diff --git a/javascript/webdriver/atoms/exports/inputs.js b/javascript/webdriver/atoms/exports/inputs.js index 50a2d5038fb1f..67c946facf2d5 100644 --- a/javascript/webdriver/atoms/exports/inputs.js +++ b/javascript/webdriver/atoms/exports/inputs.js @@ -37,3 +37,5 @@ goog.exportSymbol('webdriver.atoms.inputs.mouseMove', webdriver.atoms.inputs.mouseMove); goog.exportSymbol('webdriver.atoms.inputs.sendKeys', webdriver.atoms.inputs.sendKeys); +goog.exportSymbol('webdriver.atoms.inputs.tap', + webdriver.atoms.inputs.tap); diff --git a/javascript/webdriver/atoms/inject/BUILD.bazel b/javascript/webdriver/atoms/inject/BUILD.bazel index 2e3ac2b393f3c..8fa396938aed1 100644 --- a/javascript/webdriver/atoms/inject/BUILD.bazel +++ b/javascript/webdriver/atoms/inject/BUILD.bazel @@ -184,6 +184,15 @@ closure_fragment( ], ) +closure_fragment( + name = "tap", + function = "webdriver.atoms.inject.action.tap", + module = "webdriver.atoms.inject.action", + deps = [ + ":action", + ], +) + closure_fragment( name = "clear-local-storage", function = "webdriver.atoms.inject.storage.local.clear", diff --git a/javascript/webdriver/atoms/inject/action.js b/javascript/webdriver/atoms/inject/action.js index e884252e83303..68b71f9f16cac 100644 --- a/javascript/webdriver/atoms/inject/action.js +++ b/javascript/webdriver/atoms/inject/action.js @@ -88,6 +88,19 @@ webdriver.atoms.inject.action.click = function (element, opt_window) { [element], opt_window); }; +/** + * Tap an element. + * + * @param {bot.inject.JsonElement} element The element to tap. + * @param {bot.inject.JsonWindow=} opt_window The optional window + * containing the element. + * @return {string} A stringified {@link bot.response.ResponseObject}. + * @see bot.action.tap + */ +webdriver.atoms.inject.action.tap = function (element, opt_window) { + return webdriver.atoms.inject.action.executeActionFunction_(bot.action.tap, + [element], opt_window); +}; /** * JSON representation of a {@link bot.Mouse.State} object. diff --git a/javascript/webdriver/atoms/inputs.js b/javascript/webdriver/atoms/inputs.js index 422e707d1323b..0ccfc80ecf073 100644 --- a/javascript/webdriver/atoms/inputs.js +++ b/javascript/webdriver/atoms/inputs.js @@ -23,6 +23,7 @@ goog.provide('webdriver.atoms.inputs'); goog.require('bot.Keyboard'); goog.require('bot.Mouse'); +goog.require('bot.Touchscreen'); goog.require('bot.action'); goog.require('bot.dom'); goog.require('goog.dom'); @@ -76,6 +77,18 @@ webdriver.atoms.inputs.click = function(element, opt_state) { return mouse.getState(); }; +/** + * Tap on an element. + * + * @param {?Element} element The element to tap. + */ +webdriver.atoms.inputs.tap = function(element) { + var touchScreen = new bot.Touchscreen(); + if (!element) { + throw Error('No element to send keys to'); + } + bot.action.tap(element, null, touchScreen); +}; /** * Move the mouse to a specific element and/or coordinate location.