Seekbar
package NativeApps;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.offset.ElementOption;
import io.appium.java_client.touch.offset.PointOption;
public class Example13SeekBar {
public static void main(String[] args) throws Exception {
DesiredCapabilities dc= new DesiredCapabilities();
dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
URL url =new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver
driver.findElementsById("android:id/text1").get(10).click(); //Views
//scrolling down till we get the element
MobileElement listitem = (MobileElement) driver.findElement(
MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector()).scrollIntoView("
+ "new UiSelector().description(\"Seek Bar\"));"));
listitem.click(); //click on Seek Bar
Thread.sleep(5000);
//Locating seekbar using resource id
WebElement seekBar=driver.findElementById("io.appium.android.apis:id/seek");
//Get start point of seekbar.
int startX = seekBar.getLocation().getX();
System.out.println(startX);
//Get vertical location of seekbar.
int startY = seekBar.getLocation().getY();
System.out.println(startY);
//Get end point of seekbar.
int endX = seekBar.getSize().getWidth();
System.out.println(endX);
//Set seekbar move to position.
//endX * 0.6 means at 60% of seek bar width.
//endX * 0.9 means at 100% of seek bar width.
int moveToXDirectionAt = (int) (endX * 0.9);
System.out.println("Moving seek bar at " + moveToXDirectionAt+" In X direction.");
//Moving seekbar using TouchAction class.
TouchAction act=new TouchAction(driver);
act.press(PointOption.point(startX,startY)).moveTo(PointOption.point(moveToXDirectionAt,startY)).release().perform();
}
}