I am getting error when using the the code snippet given in appium document
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
swipeObject.put(“startX”, 0.95);
swipeObject.put(“startY”, 0.5);
swipeObject.put(“endX”, 0.05);
swipeObject.put(“endY”, 0.5);
swipeObject.put(“duration”, 1.8);
js.executeScript(“mobile: swipe”, swipeObject);
As I am using RemoteWebDriver I am not able to use driver.swipe method is there any other way I could do it?
Please use appiumdriver and do swipe like below :
First declare driver as appium driver and then instead of remote web driver do :
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub/"), capabilities);
Then for swipe you can easily use :
driver.swipe(require co-ordinates);
Above will work for sure.
As I mentioned I am Using RemoteWebDriver working on framework and I cann’t use the AndroidDriver or IOSDriver. Do you know any way to make the swipe work with RemoteWebDriver.
Hi,
U can cast RemoteWebDRiver to AndroidDriver…
Thanks,
Sudhanva
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class demo {
private AndroidDriver driver;
@BeforeClass
public void setup() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
MENTION YOUR CAPABILITIES
driver = (AndroidDriver) new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);
}
@Test
public void test() throws Exception {
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
driver.swipe(0.95,0.5,0.05,0.5,1.8);
}
thanks sudhanvam,
But i am getting exception while using this I tried this before. and is there a ways to do it just reverse of this – (RemoteWebDriver) new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”),
capabilities);
I think swipe will work with android driver only…