I have a customized Android seekbar like this, and the positions where it can move to. And it starts from the middle:
I want to move the slider first and then check if it's saved. I have a method which I use TouchAction:
public void moveSeekBar(){
WebElement seekBar = appiumDriver.findElementById("com.feverapp:id/SymptomTrackingActivity_var");
//Get start point of seekbar.
int startX = seekBar.getLocation().getX();
System.out.println(startX);
//Get end point of seekbar.
int endX = seekBar.getSize().getWidth();
System.out.println(endX);
//Get vertical location of seekbar.
int yAxis = seekBar.getLocation().getY();
//Set slidebar move to position.
// this number is calculated based on (offset + 3/4width)
int moveToXDirectionAt = 786;
System.out.println("Moving seek bar at " + moveToXDirectionAt+" In X direction.");
//Moving seekbar using TouchAction class.
TouchAction act=new TouchAction(appiumDriver);
act.press(startX,yAxis).moveTo(moveToXDirectionAt,yAxis).release().perform();
}
Something I notice that:
I tried with sendkeys like this:
seekbar.sendKeys("0.5");
and it worked: it moved the slider to the very left, and it only worked with 0.5, when I entered a number within the range from 0 to 1, it didn't work
Any help much appreciated. Thanks
@Test
public void testSeekBar()throws Exception
{
//Locating seekbar using resource id
WebElement seek_bar=driver.findElement(By.id("seek_bar"));
// get start co-ordinate of seekbar
int start=seek_bar.getLocation().getX();
//Get width of seekbar
int end=seek_bar.getSize().getWidth();
//get location of seekbar vertically
int y=seek_bar.getLocation().getY();
// Select till which position you want to move the seekbar
TouchAction action=new TouchAction(driver);
//Move it will the end
action.press(start,y).moveTo(end,y).release().perform();
//Move it 40%
int moveTo=(int)(end*0.4);
action.press(start,y).moveTo(moveTo,y).release().perform();
}
This worked for me very well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With