# Touch Actions and Mobile Web

**URL:** <https://discuss.appium.io/t/touch-actions-and-mobile-web/795>\
**Category:** Support\
**Created:** [October 9, 2014, 5:40pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795 "2014-10-09T17:40:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![vibro](https://discuss.appium.io/user_avatar/discuss.appium.io/vibro/32/5289_2.png) [@vibro](https://discuss.appium.io/u/vibro)\
**Post date:** [October 9, 2014, 5:40pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/1 "2014-10-09T17:40:52Z")

</div>

Hi all,

I’m working on testing a mobile website for both iOS and android. I knew the methods that tapped or clicked on a specific WebElement on a web browser didn’t work, so I made a workaround where I just tapped the location of the element, adjusted a bit for the screen. This solution worked in most cases.

However, I recently updated the java-client to 2.0.0 and the appium server to 1.2.3. I’m still using Selenium version 2.42.2. On iOS now, no touch actions work for me, I get a Not Yet Implemented error. I’ve also tried driver.tap(fingers, x, y, duration); but that also throws a Not Yet Implemented error. Has the way TouchActions are handled changed in the most recent release? What is the best way to do mobile web tapping, on Android or iOS?

Selenium 2.42.2  
Java-client 2.0.0  
appium 1.2.3

Mac OS 10.9.4  
iOS Emulator 6.1 (because of the issues with scrolling in 7.x)

Thanks

---

<div class="post-metadata">

**Author:** ![Hassan\_Radi](https://discuss.appium.io/user_avatar/discuss.appium.io/hassan_radi/32/4077_2.png) [@Hassan\_Radi](https://discuss.appium.io/u/Hassan_Radi)\
**Post date:** [October 9, 2014, 5:47pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/2 "2014-10-09T17:47:49Z")

</div>

Did you change how you define your driver???

I mean did you know that Java Client has a [design change](https://github.com/appium/java-client#changelog):

> There is an abstract AppiumDriver class which inherits from the Selenium Java Client. The AppiumDriver class contains all methods shared by iOS and Android. IOSDriver and AndroidDriver both extend AppiumDriver and provide more methods, and specific implementations for some methods.

---

<div class="post-metadata">

**Author:** ![vibro](https://discuss.appium.io/user_avatar/discuss.appium.io/vibro/32/5289_2.png) [@vibro](https://discuss.appium.io/u/vibro)\
**Post date:** [October 9, 2014, 5:51pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/3 "2014-10-09T17:51:16Z")

</div>

Yes, I changed that! It’s creating an iOSDriver when I launch my tests.

---

<div class="post-metadata">

**Author:** ![jonahss](https://discuss.appium.io/user_avatar/discuss.appium.io/jonahss/32/5340_2.png) [@jonahss](https://discuss.appium.io/u/jonahss)\
**Post date:** [October 9, 2014, 6:21pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/4 "2014-10-09T18:21:30Z")

</div>

If you’re automating a webview, the commands all get sent to the webdriver, through the appium driver. So if safariDriver doesn’t implement the new touchAction endpoints, it’ll spit back a NotYetImplemented error.

What you need to do is switch contexts to the NATIVE\_CONTEXT (using the contexts() methods). Run your touch actions, then switch back to the webview context.

Nothing should have changed with how it worked from before, but a couple people have run into this. I’ll take a closer look.

Tell me if the above works for you 😄

---

<div class="post-metadata">

**Author:** ![jonahss](https://discuss.appium.io/user_avatar/discuss.appium.io/jonahss/32/5340_2.png) [@jonahss](https://discuss.appium.io/u/jonahss)\
**Post date:** [October 9, 2014, 7:28pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/5 "2014-10-09T19:28:07Z")

</div>

Yeah touch actions on a webview work for me, if I stay in the native\_webview context…

---

<div class="post-metadata">

**Author:** ![Sarfaraz\_Momin](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Sarfaraz\_Momin](https://discuss.appium.io/u/Sarfaraz_Momin)\
**Post date:** [October 15, 2014, 5:30am UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/6 "2014-10-15T05:30:10Z")

</div>

hi,  
i have switch as you said but its getting hanged when control come on perform() method…

---

<div class="post-metadata">

**Author:** ![vibro](https://discuss.appium.io/user_avatar/discuss.appium.io/vibro/32/5289_2.png) [@vibro](https://discuss.appium.io/u/vibro)\
**Post date:** [October 16, 2014, 12:17pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/7 "2014-10-16T12:17:34Z")

</div>

So if I’m automating a browser (not a webview in a hybrid app) I need to change the context to NATIVE\_CONTEXT to allow touch actions?

---

<div class="post-metadata">

**Author:** ![jonahss](https://discuss.appium.io/user_avatar/discuss.appium.io/jonahss/32/5340_2.png) [@jonahss](https://discuss.appium.io/u/jonahss)\
**Post date:** [October 17, 2014, 10:23pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/8 "2014-10-17T22:23:27Z")

</div>

That is correct! ccc

---

<div class="post-metadata">

**Author:** ![Dan\_Frei](https://discuss.appium.io/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@Dan\_Frei](https://discuss.appium.io/u/Dan_Frei)\
**Post date:** [October 20, 2014, 2:58pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/9 "2014-10-20T14:58:15Z")

</div>

Hi,

I’m also facing this issue.  
I’m running the tests on a real android device (galaxy tab3) and whenever I’m trying to use Touch Actions (e.g. driver.swipe() or driver.pinch()) I’m getting this:Not Yet Implemented error.  
I’m using:  
Selenium 2.42.2  
Java-client 2.0.0  
Appium 1.2.4

Device:Galaxy Tab3  
OS: Android 4.4.2  
Browser: Chrome 38

BTW:  
I’ve tried switching the context to “NATIVE\_APP” and yet it still doesn’t work (I get a different error:An unknown server-side error occurred while processing the command).

Any Ideas?

Thanks in advance,  
Daniel.

---

<div class="post-metadata">

**Author:** ![jonahss](https://discuss.appium.io/user_avatar/discuss.appium.io/jonahss/32/5340_2.png) [@jonahss](https://discuss.appium.io/u/jonahss)\
**Post date:** [October 22, 2014, 10:41pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/10 "2014-10-22T22:41:14Z")

</div>

Definitely switch to the NATIVE\_APP context, and look at the appium logs there. The unknown error could be something like trying to swipe out of bounds or something.

---

<div class="post-metadata">

**Author:** ![Dan\_Frei](https://discuss.appium.io/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@Dan\_Frei](https://discuss.appium.io/u/Dan_Frei)\
**Post date:** [October 23, 2014, 7:47am UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/11 "2014-10-23T07:47:45Z")

</div>

Hi Jonahss,

Thank you for the assistance!  
Eventually I’ve been able to successfully execute TouchActions (swipe, tap etc…) by switching the driver to NATIVE\_APP as you’ve suggested.

I now understand, that currently, appium supports Touch Actions only in native context (otherwise, I got a "Not implemented yet…error).  
Unless I’m wrong, this means that if one desires to utilize the the benefits of TouchActions while testing a Mobile Web, he should get the coordinates of the WebElement he wants to manipulate via a TouchAction, switch to Native context, execute the touch command via an api that accepts X,Y coordinates and then, switch the driver back to the previous context like in the following pseudocode:

WebElement element = driver.findElement(By.id(“testElement”));  
Point point = element.getLocation();  
Dimension size = element.getSize();

int elementCenterX = point.getX() + Math.round(size.getWidth() / 2);  
int elementCenterY = point.getY() + Math.round(size.getHeight() / 2);

String originalContext = driver.getContext();  
driver.context(“NATIVE\_APP”);

driver.tap(1, elementCenterX , elementCenterY , 1000);

driver.context(originalContext );

Unfortunately, I still face problems trying to utilize TouchActions for mobile-web testing purposes.  
The major problem, is the difference between the X,Y reference point that is used in “NATIVE-APP” context and the one that is used in “WEBIEW”.  
It looks like in “NATIVE-APP” mode, the driver regards the X,Y coordinates relatively to the physical screen in device pixels (screenXY), whilst in “WEBVIEW” mode, the driver regards the X,Y coordinates relatively to the to the top left of the fully rendered content area in the browser in CSS pixels (pageXY).

This means, that in-order to make things work, we need to somehow transform the aforementioned WebElement’s PageXY coordinate to a screenXY coordinate.

I’ve tried several approaches to solve this issue - unfortunately without success.

Approach #1(use org.openqa.selenium.internal.Locatable to get the “onScreen” coordinate):  
Point onScreen = ((Locatable)element).getCoordinates().onScreen();  
Result: Fails - I get an error saying that AppiumDriver doesn’t support the method: onScreen()

Approach #2 (Calculate the offset between the two reference points)  
In order to do so, one of the basic things we need to do is getting the window size:  
driver.manage().window().getSize();  
Result: Fails -I get an error saying that AppiumDriver doesn’t support window().

Would appreciate your kind advice!

Thanks again and Best Regards,  
Daniel.

---

<div class="post-metadata">

**Author:** ![jonahss](https://discuss.appium.io/user_avatar/discuss.appium.io/jonahss/32/5340_2.png) [@jonahss](https://discuss.appium.io/u/jonahss)\
**Post date:** [October 24, 2014, 5:07pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/12 "2014-10-24T17:07:34Z")

</div>

Aha, that is a good point. We should find a way to transform the coordinates. Can you create an issue on the githug repo please?

---

<div class="post-metadata">

**Author:** ![Dan\_Frei](https://discuss.appium.io/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@Dan\_Frei](https://discuss.appium.io/u/Dan_Frei)\
**Post date:** [October 25, 2014, 9:05pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/13 "2014-10-25T21:05:51Z")

</div>

Thanks jonahss!

I’ve created an issue in the github as requested:

> <https://github.com/appium/appium/issues/3896>
>
> Currently, appium supports Touch Actions only in native context (otherwise, a "N…ot implemented yet...exception is thrown).
> This means, that if one desires to utilize the the benefits of TouchActions in favor of testing a Mobile Web, he should get the coordinates of the WebElement he wants to manipulate via a TouchAction, switch to Native context, execute the touch command via an api that accepts X,Y coordinates and then, switch the driver back to the previous context like in the following pseudocode:
> 
> WebElement element = driver.findElement(By.id("testElement"));
> Point point = element.getLocation();
> Dimension size = element.getSize();
> 
> int elementCenterX = point.getX() + Math.round(size.getWidth() / 2);
> int elementCenterY = point.getY() + Math.round(size.getHeight() / 2);
> 
> String originalContext = driver.getContext();
> driver.context("NATIVE\_APP");
> 
> driver.tap(1, elementCenterX , elementCenterY , 1000);
> 
> driver.context(originalContext );
> 
> Unfortunately, one will still face problems trying to utilize TouchActions for mobile-web testing purposes. 
> The major problem is the difference between the X,Y reference point that is used in "NATIVE-APP" context and the one that is used in "WEBIEW".
> It looks like in "NATIVE-APP" mode, the driver regards the X,Y coordinates relatively to the physical screen in device pixels (screenXY), whilst in "WEBVIEW" mode, the driver regards the X,Y coordinates relatively to the to the top left of the fully rendered content area in the browser in CSS pixels (pageXY).
> 
> This means, that in-order to make things work, we need to somehow transform the aforementioned WebElement's PageXY coordinate to a screenXY coordinate.
> 
> I've tried several approaches to solve this issue - unfortunately without success.
> 
> Approach #1(use org.openqa.selenium.internal.Locatable to get the "onScreen" coordinate):
> Point onScreen = ((Locatable)element).getCoordinates().onScreen();
> Result: Fails - I get an error saying that AppiumDriver doesn't support the method: onScreen()
> 
> Approach #2 (Calculate the offset between the two reference points)
> In order to do so, one of the basic things we need to do is getting the window size:
> driver.manage().window().getSize();
> Result: Fails -I get an error saying that AppiumDriver doesn't support window().

Thanks & Best Regards,  
Daniel.

---

<div class="post-metadata">

**Author:** ![vibro](https://discuss.appium.io/user_avatar/discuss.appium.io/vibro/32/5289_2.png) [@vibro](https://discuss.appium.io/u/vibro)\
**Post date:** [October 27, 2014, 2:57pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/14 "2014-10-27T14:57:16Z")

</div>

I’ve been getting around this by hardcoding an offset, but it’s not the most reliable method.

---

<div class="post-metadata">

**Author:** ![Sarfaraz\_Momin](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Sarfaraz\_Momin](https://discuss.appium.io/u/Sarfaraz_Momin)\
**Post date:** [October 28, 2014, 4:54am UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/15 "2014-10-28T04:54:40Z")

</div>

hi,  
actually, I have faced this kind of error when i was using like e.g. tap(button).perform()  
then I used (X,Y) co-ord but Y co-ord is not correctly located on screen while X co-ord is correct so i add some offset (in my case i add 100 i.e. Y+100) then its worked for me.  
But i dont think this is the reliable way to do this job.

---

<div class="post-metadata">

**Author:** ![maxski](https://discuss.appium.io/letter_avatar_proxy/v4/letter/m/8491ac/32.png) [@maxski](https://discuss.appium.io/u/maxski)\
**Post date:** [November 3, 2014, 12:33pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/16 "2014-11-03T12:33:31Z")

</div>

Hi guys!  
Has anybody got it resolved? Please share your results as hardcoded Y offset couldn’t be worked for different mobiles as they have different resolutions.

---

<div class="post-metadata">

**Author:** ![maxski](https://discuss.appium.io/letter_avatar_proxy/v4/letter/m/8491ac/32.png) [@maxski](https://discuss.appium.io/u/maxski)\
**Post date:** [November 3, 2014, 6:29pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/17 "2014-11-03T18:29:11Z")

</div>

Eric knows another workaround, how to get this resolved.  
But it also works unstable:-(

> [@Get screen and browser size](https://discuss.appium.io/t/get-screen-and-browser-size/764):
>
> Hello, I’m using Appium in Ruby on Android real device Galaxy S4 I’m looking to get the screen and browser size but right now I’m using, after opening my webpage on Chrome: @browser.execute\_script(“return window.innerWidth”).to\_i @browser.execute\_script(“return window.innerHeight”).to\_i @browser.execute\_script(“return window.outerWidth”).to\_i @browser.execute\_script(“return window.outerHeight”).to\_i @browser.execute\_script(“return screen.width”).to\_i @browser.execute\_script(“return scree…

---

<div class="post-metadata">

**Author:** ![pess](https://discuss.appium.io/letter_avatar_proxy/v4/letter/p/47e85d/32.png) [@pess](https://discuss.appium.io/u/pess)\
**Post date:** [November 6, 2014, 2:41pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/18 "2014-11-06T14:41:50Z")

</div>

```
public static void tap(WebElement we) {
    Point p = we.getLocation();
    Dimension size = we.getSize();
    try {
      nativeContext();
      Point appLoc = driver.findElement(By.xpath("//UIAWebView[1]")).getLocation();
      driver.tap(1, appLoc.x + p.x + (size.width / 2), appLoc.y + p.y + (size.height / 2), 1);
    } finally {
      webContext();
    }
  }
```

---

<div class="post-metadata">

**Author:** ![maxski](https://discuss.appium.io/letter_avatar_proxy/v4/letter/m/8491ac/32.png) [@maxski](https://discuss.appium.io/u/maxski)\
**Post date:** [November 6, 2014, 4:06pm UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/19 "2014-11-06T16:06:47Z")

</div>

Hi,

This doesn’t work for me:

> Point appLoc = driver.findElement(By.xpath(“//UIAWebView[1]”)).getLocation();

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.

---

<div class="post-metadata">

**Author:** ![maxski](https://discuss.appium.io/letter_avatar_proxy/v4/letter/m/8491ac/32.png) [@maxski](https://discuss.appium.io/u/maxski)\
**Post date:** [November 7, 2014, 8:39am UTC](https://discuss.appium.io/t/touch-actions-and-mobile-web/795/20 "2014-11-07T08:39:12Z")

</div>

Smth that worked on one phone. failed on another…  
Is there any ideas how to get correct coordinates for tap?

@jonahss  
Looks, this can be fixed in 1.3.2. When are you going to release 1.3.2?

[Next page](https://discuss.appium.io/t/touch-actions-and-mobile-web/795.md?page=2)
