@Telmo_Cardoso thanks for the help.
after importing those file i am getting error in WaitOptions
i don’t know why eclipse was not taking that automatically.
thank you @Telmo_Cardoso
Hi Telmo,
Please help me with the below code,
MobileElement elmUserName = (AndroidElement) driver.findElement(By.id(“username”));
ElementOption eoption;
eoption = new ElementOption().withElement(elmUserName);
TouchActions act = new TouchActions(driver);
act.longPress((WebElement) LongPressOptions.longPressOptions().withElement(eoption)).build().perform();
**I am getting below error message
Mar 27, 2018 12:52:57 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread “main” java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen
at org.openqa.selenium.interactions.touch.TouchActions.(TouchActions.java:38)
at scripts.TouchActionExample.main(TouchActionExample.java:39)
I am using Java Client 6.0.0. Beta 4 and Selenium-Standalone-server 3.11 jars.
I have a class called Utils were I defined some useful methods, and I have a construction which is passing me the driver( sorry still at the beginning of appium and java and I might get it wrong).
Here is my code:
package resources;
import static io.appium.java_client.touch.TapOptions.tapOptions;
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static io.appium.java_client.touch.offset.ElementOption.element;
import static io.appium.java_client.touch.offset.PointOption.point;
import static java.time.Duration.ofSeconds;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
public class Utils {
public static AndroidDriver<AndroidElement> driver;
public Utils(AndroidDriver<AndroidElement> driver) {
Utils.driver = driver;
}
public void swipe(int x_start, int y_start, int x_stop, int y_stop, int duration) {
new TouchAction(driver).press(point(x_start, y_start)) .waitAction(waitOptions(ofSeconds(duration)))
.moveTo(point(x_stop, y_stop)) .release() .perform();
}
The driver is initiating in my TestBase class.
I use java-client 6.1.0 + Desktop 1.6.2, and TouchAction.tap()
with WebElement throws UnsupportedCommandException:
org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.13.0', revision: '2f0d292'
Apparently Appium server doesn’t support touch yet because the command errors out (404):
[HTTP] --> POST /wd/hub/session/a304c963-e881-4b3c-a0e1-13f32db993b5/touch/perform
[HTTP] {"actions":[{"action":"tap","options":{"element":"0.09312566293240376-11"}}]}
[W3C] Calling AppiumDriver.performTouch() with args: [[{"action":"tap","options":{"element":"0.09312566293240376-11"}}],"a304c963-e881-4b3c-a0e1-13f32db993b5"]
[HTTP] <-- POST /wd/hub/session/a304c963-e881-4b3c-a0e1-13f32db993b5/touch/perform 404 3 ms - 4088
Is there a workaround?
Installed appium server 1.8.1. Same result.
[HTTP] --> POST /wd/hub/session/20d48a51-2a62-43ad-9dda-0acf7f3699d6/touch/perform
[HTTP] {"actions":[{"action":"tap","options":{"element":"0.4547671076436339-11"}}]} [debug] [W3C] Calling AppiumDriver.performTouch() with args:[[{"action":"tap","options":"element":"0.4547671076436339-11"}}],"20d48a51-2a62-43ad-9dda-0acf7f3699d6"]
[HTTP] <-- POST /wd/hub/session/20d48a51-2a62-43ad-9dda-0acf7f3699d6/touch/perform 404 17 ms - 3575
SOLVED – See this post on SO32. The author literally saved my week!
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(“deviceName”, “emulator-5554”);
dc.setCapability(“BROWSER_NAME”, “android”);
dc.setCapability(“platformName”, “Android”);
dc.setCapability(“appPackage”, “com.poshmark.app”);
dc.setCapability(“appActivity”, “com.poshmark.ui.MainActivity”);
try {
driver = new RemoteWebDriver(new URL(“http://127.0.0.1:4723/wd/hub”), dc);
wait = new WebDriverWait(driver, 10);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
io.appium.java_client.TouchAction action = new TouchAction((MobileDriver)driver);
action.press(PointOption.point(startx, starty)).moveTo(PointOption.point(startx, endy)).release().perform();
I tried this code, but error occured
Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver cannot be cast to io.appium.java_client.MobileDriver
at com.appium.example.FirstAppiumTest.scrollDown(FirstAppiumTest.java:194)
at com.appium.example.FirstAppiumTest.GatherName(FirstAppiumTest.java:206)
at com.appium.example.FirstAppiumTest.actionPerformed(FirstAppiumTest.java:176)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Please need help!!!
AddNote: I am using java-client6.1.0.jar
Could you please share us, LongPress on coordinates with duration? I have tried but I can’t. What I have tried
//LongPress on coordinates with duration:
new TouchAction((AndroidDriver)driver).longPress(longPressOptions().withElement((ElementOption) point(xPoint, yPoint)).withDuration(Duration.ofMillis(duration))).release().perform();