How to get the co-ordinates to scroll up and down

Hi All,

I’m new to appium, i was trying to a partial scroll on my screen on both android and iOS. I was unable to get it worked by any method.

Followed the link below-- didn’t help me understanding on how to get the co-ordinates can someone help me on this .

Tried : driver.swipe(50, 50, 20, 20, 22) this performs a click and gets back out of the current screen .

Can someone help me understand how to get the startX,startY and endX and endY co-ordinates

Regards,
Sai

@bootstraponline can you please me on this … As I’m.working on POC to jump from calabash to android …swipe and scroll are very important for me for both android and iOS … Can you please help me on this ?

All the appium clients and the appium server have working tests that demo swipe & scroll.

@bootstraponline thanks for the link. But i still haven’t got an idea on how to get the co-ordinates from the application to scroll partially on the screen.From the image below i just want to scroll the first listing up. How can this be done?

Its a UITableView not scroll view

Get the element and with the element get location and size

ele.location.x
ele.location.y
ele.size.height
ele.size.width

now you can find out a middle point for your element. Start your swipe there and the end point of swipe will be the height of the element

http://appium.github.io/java-client/io/appium/java_client/AppiumDriver.html#swipe(int,%20int,%20int,%20int,%20int)

@Telmo_Cardoso thanks for the inputs, i tried the way you mentioned but it clicks the element does not scroll

driver.swipe(ele.getLocation().getX(), ele.getLocation().getY(), ele.getSize().getHeight(), ele.getSize().getWidth(), 1000);

Above code is what i used. It clicks on the element but does not scroll

I’m using ruby, so it may have typo’s

void swipeUpElement(AppiumDriver driver, MobileElement element, int duration){
    int topY = element.getLocation().getY()
    int bottomY = topY + element.getSize().getHeight()
    int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2)
    driver.swipe(centerX, bottomY, centerX, topY, duration);
}

For a swipe down of the height of element its the same logic. Just invert the Y

@Telmo_Cardoso that didn’t work, the screen didn’t scroll up.

public void swipeUpElement(AppiumDriver driver, MobileElement element, int duration){
int topY = element.getLocation().getY();
int bottomY = topY + element.getSize().getHeight();
int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2);
driver.swipe(centerX, bottomY, centerX, topY, duration);
}

MobileElement element = (MobileElement) driver.findElement(By.xpath("//*[@name=‘anonymous_shop_btn’]"));
swipeUpElement(driver, element, 2000);

Please find the appium stack trace
info: [debug] [INST] 2014-12-23 17:26:15 +0000 Debug: Got new command 20 from instruments: au.dragApp(187,530,187,495,2)
info: [debug] [INST] 2014-12-23 17:26:15 +0000 Debug: evaluating au.dragApp(187,530,187,495,2)
info: [debug] [INST] 2014-12-23 17:26:15 +0000 Debug: target.dragFromToForDuration({x:“187”, y:“530”}, {x:“187”, y:“495”}, “2”)

info: [debug] Socket data received (25 bytes)

info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {“status”:0,“value”:""}

info: [debug] [INST] 2014-12-23 17:26:17 +0000 Debug: evaluation finished
info: [debug] [INST] 2014-12-23 17:26:17 +0000 Debug: responding with:
info: [debug] [INST] 2014-12-23 17:26:17 +0000 Debug: Running system command #21: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:""}…

info: [debug] Responding to client with success: {“status”:0,“value”:"",“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: <-- POST /wd/hub/session/7fce5bc9-92f9-474d-a370-c063cd34c7c3/touch/perform 200 4192.604 ms - 74 {“status”:0,“value”:"",“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: [IOS_SYSLOG_ROW ] Dec 23 22:56:28 — last message repeated 1 time —

info: [IOS_SYSLOG_ROW ] Dec 23 22:56:28 Sais-MacBook-Air-2 com.apple.CoreSimulator.SimDevice.41B6881E-2278-4F26-BBE9-B782876D9462.launchd_sim[48233] (com.apple.imfoundation.IMRemoteURLConnectionAgent): The _DirtyJetsamMemoryLimit key is not available on this platform.

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.661 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.552 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.605 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.531 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.646 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.681 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.449 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: --> GET /wd/hub/status {}

info: [debug] Responding to client with success: {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}
info: <-- GET /wd/hub/status 200 0.542 ms - 178 {“status”:0,“value”:{“build”:{“version”:“1.3.3”,“revision”:“34e21b01b87d4e3959e1c97c0a8d0b1a610bdc78”},“isShuttingDown”:false},“sessionId”:“7fce5bc9-92f9-474d-a370-c063cd34c7c3”}

info: [IOS_SYSLOG_ROW ] Dec 23 22:56:58 — last message repeated 1 time —

info: [IOS_SYSLOG_ROW ] Dec 23 22:56:58 Sais-MacBook-Air-2 com.apple.CoreSimulator.SimDevice.41B6881E-2278-4F26-BBE9-B782876D9462.launchd_sim[48233] (com.apple.imfoundation.IMRemoteURLConnectionAgent): The _DirtyJetsamMemoryLimit key is not available on this platform.

info: --> DELETE /wd/hub/session/7fce5bc9-92f9-474d-a370-c063cd34c7c3 {}

info: Shutting down appium session
info: [debug] Stopping ios
info: [debug] Destroying instruments client socket.
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Sending sigterm to instruments

info: [debug] [INST] 2014-12-23 17:26:59 +0000 Stopped: Script was stopped by the user
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2.local SpringBoard[48244]: Unable to get short BSD proc info for 48274: No such process
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2 com.apple.CoreSimulator.SimDevice.41B6881E-2278-4F26-BBE9-B782876D9462.launchd_sim[48233] (UIKitApplication:com.tesco.grocery[0x750f][48274]): Service exited due to signal: Killed: 9

info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2.local SpringBoard[48244]: Application ‘UIKitApplication:com.tesco.grocery[0x750f]’ exited abnormally via signal.
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2 assertiond[48248]: assertion failed: 14B25 12A365: assertiond + 11619 [03CE1BE5-ACCB-3989-A453-41D167A25E66]: 0x1
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2.local assertiond[48248]: notify_suspend_pid() failed with error 7
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2 assertiond[48248]: assertion failed: 14B25 12A365: assertiond + 11619 [03CE1BE5-ACCB-3989-A453-41D167A25E66]: 0x1

info: [debug] [INST] Instruments Trace Complete (Duration : 105.777145s; Output : /tmp/appium-instruments/instrumentscli0.trace)

info: [debug] [INSTSERVER] Instruments exited with code 0
info: [debug] Cleaning up after instruments exit
info: [debug] Stopping iOS log capture
info: [debug] Running ios sim reset flow
info: [debug] Killing the simulator process
info: [debug] Killall iOS Simulator
info: [debug] Killing any other simulator daemons
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2.local DTMobileIS[48252]: Could not create service named com.apple.instruments.server.services.launchdaemon
info: [IOS_SYSLOG_ROW ] Dec 23 22:56:59 Sais-MacBook-Air-2.local DTMobileIS[48252]: Could not create service named com.apple.instruments.server.services.processcontrol.posixspawn

@Telmo_Cardoso can you paste your ruby code to scroll up and down. That would help me please

That code should work, except the duration. Its in ms, so send 2000 for example.

You can take a look at TouchAction class

@Telmo_Cardoso the above comment worked on Java … i’m working on the ruby base… i tried to get the coordinate by element.getLocation it throws exception.

From the screenshot above, i get n+1 element with same :name/id the scenario is like
when the first 3 element in the screen is disabled i need to perform a scroll and then check…

can you share the code for scroll

To scroll down with ruby, no matter what elements, you should be able with:

swipe(:start_x => 0 :start_y => 450, :end_x => 0, :end_y => 250, :duration => 2000)

or just:

Appium::TouchAction.new.swipe(start_y: 400, end_y: -400).perform

maybe the old javascript method still works:

execute_script 'mobile: scroll', :direction => 'down'

Using the console (arc) just try to explore the endless possibilities :slight_smile:

@Telmo_Cardoso Thanks a lot the below command worked

I have an other trouble, how can i get only the elements that are present on the screen, currently on a ListView/TableView i get all the elements property which are not seen on the screen as well

It depends on what you want to do. One easy way to see is getting the location.y of each element. If the value is negative then its above current screen. If it is larger than the app height size is below the current screen.

To get the app height size, just the identify the main container (adapt code below to your container type) and request the size like this:

tag("android.widget.LinearLayout").size.width
tag("android.widget.LinearLayout").size.height

For different questions open new topic. Its easier for future users to identify their own problems.

You can get the Co-ordinates by going to Developer Option-> Pointer Location if you are you using Android.

1 Like

this also works

execute_script 'UIATarget.localTarget().flickFromTo({x:300, y:200},{x:50, y:200})'

Hi @Telmo_Cardoso ,
I have tried with you above code got the below error.
Error: “An element could not be located on the page using the given search parameters.”
Here element won’t be visible so that how can we pass as argument in that, due to that in the very first line of scroll logic got failed.

Code:

MobileElement element = driver.findElement(By.name(“Location”));

	int topY = element.getLocation().getY();
		    int bottomY = topY + element.getSize().getHeight();
		    int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2);
		    driver.swipe(centerX, bottomY, centerX, topY, 3000);
		element.click();

This worked for iOS, is this good for android too?

Also refer to Swipe/Scroll best practice with Java-Client 5