1

enter image description hereI wrote a code for SeekBar.

I wanted to move the SeekBar but it did not move.

When I run the code it gives me values in the console but did not move.

Kindly check my code and tell me what I am missing in this,

    Base.java ;
    
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.android.AndroidElement;
    import io.appium.java_client.remote.MobileCapabilityType;
    
    public class base {
        
        public static  AndroidDriver<AndroidElement> capabilities() throws MalformedURLException
        {
            
             File f = new File("src");
             File fs = new File(f, "tesjo.apk");
            
            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(MobileCapabilityType.DEVICE_NAME,"Galaxy A10s");
            cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Uiautomator2");
            cap.setCapability(MobileCapabilityType.VERSION, "10");
            cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
            cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
             cap.setCapability("chromedriverExecutable", "C:/Users/LENOVO L540/Downloads/chromedriver_win32 (1)/chromedriver.exe");
                
            AndroidDriver<AndroidElement>driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
            
                     
             return driver ;
            
    
        }
    
    }



Tesjocalss ;

import static java.time.Duration.ofSeconds;

import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.offset.PointOption;
import static io.appium.java_client.touch.LongPressOptions.longPressOptions;

import static io.appium.java_client.touch.offset.ElementOption.element;


public class demotesjo extends base {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        // TODO Auto-generated method stub
        AndroidDriver<AndroidElement>driver=capabilities();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.findElementById("com.android.permissioncontroller:id/permission_allow_foreground_only_button").click();
        driver.findElement(By.id("com.mytesjo.android:id/nav_bottom_profile")).click();
        driver.findElementByAndroidUIAutomator("text(\"Email\")").sendKeys("hamza@student.com");
        driver.findElement(By.xpath("//*[@text='Password']")).sendKeys("12345678");
        driver.findElement(By.id("com.mytesjo.android:id/login_student_RB")).click();
        driver.findElement(By.id("com.mytesjo.android:id/login_BTN")).click();
        
        Thread.sleep(2000);
        
        driver.findElement(By.id("com.mytesjo.android:id/nav_bottom_home")).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("//*[@text='Teacher']")).click();
        Thread.sleep(2000);
        
        
        MobileElement seekBar = (MobileElement) driver.findElementById("com.mytesjo.android:id/price_seekbar");
        
// get start co-ordinate of seekbar
    int start = seekBar.getLocation().getX();
    System.out.println(start);
    // Get width of seekbar
    int end = seekBar.getSize().getWidth();
    System.out.println(end);
    // get location of seekbar vertically
    int y = seekBar.getLocation().getY();
    System.out.println(start);

    // Select till which position you want to move the seekbar
    TouchAction action = new TouchAction(driver);

    // Move it 40%
    int moveToXDirectionAt = (int) (end * 0.4);
    System.out.println("Moving seek bar at " + moveToXDirectionAt+" In X direction.");
    action.longPress(PointOption.point(start,y)) .moveTo(PointOption.point(moveToXDirectionAt,y)) .release().perform();
    
  
        }
         
        
        
        
    }



console output ,
0
720
0
Moving seek bar at 288 In X direction.
2
  • please add the screen shot of the element and activity
    – PDHide
    Mar 9 at 10:58
  • @PDHide kindly check Mar 9 at 11:17
1
 action.longPress(PointOption.point(0, y)).moveTo(PointOption.point(moveToXDirectionAt, y)).release().perform();

your code is correct , the issue is the starting position i guess. Start from zero

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.