How to get device id


Is there a way to get the device id and run few scripts. for example
if (Deviceid == 4100951cf20c1215")) {

Please help me to get the device id and store it in a variable.

Do you mean the uuid? You don’t mention what platform so I’ll give you iOS:

‘instruments -s devices’

In my test framework I call this, parse the results and match the device name with the one the user put in settings.


I am looking for android. Can you please help.

Find Android device’s model name:

adb devices -l

Find Android device’s version no:

adb shell getprop

But how do I add this in the appium code. This I run from the terminal right?

In my framework we run a command like this in the setup, and then start the server using this value. You can make a system call from whatever language you are using to adb. You will probably need to parse the results and store the uuid in a variable.

1 Like

Connect your android mobile to your computer using USB cable.
Then type below command in the terminal
adb devices -l

It will display all the connected device to your comaputer with device IDs.

And you can pass the device ID to your code using DesiredCapabilities
eg: if your device id is f23a5A83,

DesiredCapabilities Androidcapability=new DesiredCapabilities();
Androidcapability.setCapability(“udid”, “f23a5A83”);

1 Like

Below is the code I tried and works fine

java.lang.Runtime rt = java.lang.Runtime.getRuntime();
// Start a new process: UNIX command ls
java.lang.Process p = rt.exec(“adb devices”);
// Get process’ output: its InputStream is = p.getInputStream(); reader = new InputStreamReader(is));
// And print each line
String s= (reader.readLine());

	while ((s = reader.readLine()) != null) {

There are a couple known ways to retrieve Android device IDs. The first, most straightforward method is already listed in this thread: Spawn a child process that runs “adb devices” and then parse the results that are returned on the child’s standard out. Although this will work, I feel that it’s a bit shaky since your parent process will need a PATH environment variable that contains adb, and parsing the results is often frustrating to set up.

For Java, I think a better option is to include the same device library the Android SDK uses into your own test framework. Check out ddmlib and a ddmlib demo to get a feel for how to use it to retrieve devices. The downside is that you still have to be able to find adb, but you won’t have to deal with parsing the results.

1 Like

Can any one help to get the version and device id for IOS device.

@Harish_pedamallu check the first reply to this topic made by wreed.

Hi, Can you show me Example how you do it ? call ‘instruments -s devices’ from framwork (Im using JAVA) and, parse the results (UDID) to String Array List ?

Thanks !!! :slight_smile:

Here is a tutorial on making a system call in Java:

The example above from @tapanagkumar is a good one.

I will try it,

Thanks ! :slight_smile: