Hi all,
While practicing appium i have a requirement to scroll towards right side, for that i am trying “mobile: scroll”
I heard a bug exists at below link.
mobile: scroll not work on Android
Here is what i need:
Lauch api demos ->Views -> Tabs -> 5. Scrollable and then i want to scroll to Tab
8(Which we need to scroll to left to see the Tab 8). How can i do this
in Android. I am trying below, but returning " TypeError: string is not a
function" error message.
Following is the code i am trying:
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebElement;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ScrollToExample
{
AndroidDriver driver;
@BeforeTest()
public void launch()
{
DesiredCapabilities capabilities=new DesiredCapabilities();
capabilities.setCapability("deviceName", "Testing");
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", "ApiDemos");
try
{
driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Test
public void ScrollToEle() throws Exception
{
driver.scrollTo("Views").click();
driver.scrollTo("Tabs").click();
driver.findElementByAndroidUIAutomator("text(\"5. Scrollable\")").click();
Thread.sleep(5000);
WebElement tab4=driver.findElementByAndroidUIAutomator("text(\"Tab 4\")");
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "left");
scrollObject.put("element",((RemoteWebElement) tab4).getId());
scrollObject.put("text", ((RemoteWebElement) tab4).getText());
js.executeScript("mobile: scroll", scrollObject);
}
}
Following is the error message i am getting after clicking on Scrollable element:
TypeError: string is not a function