How to Handle (drag) Seek bar in Android?

Hi,

Is there any specific method to drag seek bar up to some extent?
Please let me know if any one knows !!!

Thank you in advance,
Bhaskar.

There is no specific method provided by appium. You have to use touchActions

@Test
public void SeekBarTest(){
WebElement slider=driver.findElementById(“com.android.:id/seekBar1”);
int xAxisStartPoint = slider.getLocation().getX();
int xAxisEndPoint = xAxisStartPoint + slider.getSize().getWidth();
int yAxis = slider.getLocation().getY();
TouchAction act=new TouchAction(driver);
//pressed x axis & y axis of seekbar and move seekbar till the end
act.press(xAxisStartPoint,yAxis).moveTo(xAxisEndPoint-1,yAxis).release().perform();
}

Coordinates are in u r hands to use. % movement You can decide based on that.

3 Likes

How to move to specific value
Like i have seek bar
Starting range is 10% and Ending Range 60%
showing 35% by default
i have to move by 5% only towards backwardside or forwardside
then how to implement that
i used above funtion it is going forward i.e to 60%
i have to move 40% or 30%
please suggest me
what should i passed value

Hi @rohal,

You need to vary xAxisStartPoint in both press and release functions until you get it.

Regards,
Bhaskar.

FOR IOS how to handle seekbar?

Hi,

These is easy way to use seekbar to move upto some specific postion with below code
//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 40%
    int moveTo=(int)(end*0.4);
    action.press(start,y).moveTo(moveTo,y).release().perform();

For complete explaination visit my blog -
http://qaautomated.blogspot.in/2016/02/how-to-move-seek-bar-with-appium.html

2 Likes

@bhaskar

Please tell me how to move this seekbar from right to left direction.

Please use the following code to automation seek bar,

        /**
 * Automates slider or seek bar to the desired value provided
 * @param elementType: Element identification type as string (ID,XPATH,CSS etc)
 * @param elementName: Element name (ID value, XPATH value etc)
 * @param intToSlideValue: Value to which element needs to be slided(0 to 100)
 * @author chethanshetty
 */
public void setSliderValue(String elementType, String elementName, int intToSlideValue) {
	WebElement seekBar = getElement(elementType, elementName);
	
	//Get start point of seekbar.
    int startX = seekBar.getLocation().getX();
    
    //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 = intToSlideValue + startX;
    
    //Moving seekbar using TouchAction class.
    TouchAction act=new TouchAction(DriverSingleton.getInstance().getMobileDriver());
    act.longPress(startX,yAxis).moveTo(moveToXDirectionAt,yAxis).release().perform();
}

The above code makes use of long press to automate seek bar.
For more info please refer this link

@chethan_shetty_c,

I’m adding few info to your suggestion,
We may vary coordinates (x and y) based on our requirement.

@bhaskar please check the updated answer. Now you can use this method and pass the value to be slided . Please feel free to tweak as your requirement.

Great @chethan_shetty_c,
That will be very useful.

1 Like

Thank you so much - your solution worked perfectly for me!

driver.findElementByAccesiblityID(“<name_of_the_Element>”).sendKeys(“0.5”);

We can set 0 to 1. If you pass 0 it sets to 0, 1 to 100% on slider. But it not working in the latest Applum 1.6.4. They are working on it.

2 Likes

This works ! thanks anuja :slight_smile:

Thank you, your code is better working for me

Hi guys, I’m also using same way but its always redirecting my video at particular time that is 41:40. I have raised an issue for that also. Please have a look into it and help if you know the solution.