Appium Beginner Tutorial 9 | How to use UIAutomatorViewer for Object Locators
Vložit
- čas přidán 21. 08. 2024
- FREE courses - automationstep...
IMP - In case you do not find uiautomatorviewer.bat, check this user comment:
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmana...
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow....
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/...
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
Step 1 : Connect mobile device to computer system
through cable OR through wifi
• Appium Step by Step fo...
Step 2 : Run command adb devices
Step 3 : Start UIAutomatorViewer
Windows - goto android-sdk/tools/bin
Mac - from terminal run command uiautomatorviewer
Step 4 : Open the application on mobile device and capture on uiautomatorviewer to find element locators
#AppiumBeginnerTutorial
FREE Courses - automationstep...
Udemy - www.udemy.com/...
Training by Raghav at your venue - raghav.qna@gmail.com
Training schedule - automationstep...
----------- UI TESTING -----------
Selenium Beginners - bit.ly/2MGRS8K
Selenium Java Framework from Scratch - bit.ly/2N9xvR6
Selenium Python - bit.ly/2oyMp5x
Selenium Tips - bit.ly/2owxc50
Selenium Builder - bit.ly/2MKNtlq
Katalon Studio - bit.ly/2wARFdi
Robot Framework with RIDE- bit.ly/2Px6Ue9
Robot Framework with Eclipse - bit.ly/2N8DZxb
----------- API TESTING -----------
Web Services (API) - bit.ly/2MGafL7
SoapUI - bit.ly/2MGahmd
Postman - bit.ly/2wz8LrW
General - bit.ly/2PYdwmV
Katalon Studio API Testing - bit.ly/2BwuCTN
----------- MOBILE TESTING -----------
Appium - bit.ly/2ZHFSGX
Mobile Playlist - bit.ly/2PxpeUv
----------- CI | CD | DEVOPS -----------
Jenkins Beginner - bit.ly/2MIn8EC
Jenkins Tips & Trick - bit.ly/2LRt6xC
Docker - bit.ly/2MInnzx
----------- VERSION CONTROL SYSTEM -----------
Git & GitHub - bit.ly/2Q1pagY
----------- PERFORMANCE TESTING -----------
JMeter Beginner - bit.ly/2oBbtIU
JMeter Intermediate - bit.ly/2oziNVB
JMeter Advanced - bit.ly/2Q22Y6a
JMeter Tips & Tricks - bit.ly/2NOfWD2
Performance Testing - bit.ly/2wEXbLS
----------- PROGRAMMING -----------
Java Beginners - bit.ly/2PVUcXs
Java Tips & Tricks - bit.ly/2CdcDnJ
GROOVY - bit.ly/2FvWV5C
----------- IDE -----------
Visual Studio Code - bit.ly/2V15yvt
----------- MAVEN -----------
Maven - bit.ly/2NJdDRS
----------- OTHERS -----------
Redis- bit.ly/2N9jyCG
Misc - bit.ly/2Q2q5xQ
Tools & Tips - bit.ly/2oBfwoR
QnA Friday- bit.ly/2NgwGpw
Sunday Special - bit.ly/2wB23BO
Ask Raghav - bit.ly/2CoJGWf
Interviews - bit.ly/2NIPPxk
All Playlists - bit.ly/2LSiezA
Never Stop Learning,
Raghav
Udemy Courses - www.udemy.com/...
CZcams - / automationstepbystep
You can support my mission for education by sharing this knowledge and helping as many people as you can
**IMP**
In case you do not find *uiautomatorviewer.bat*, check this user comment:
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/android/repository/sdk-tools-windows-3859397.zip
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
Sir if there's no resources ID appearing, what should I do next for me to interact with that element using my code?
Can use other locators or check with some diff app
@raghavpal I hv downloaded latest Android studio jellyfish. Not able to find uiautomator file and tools folder itself Kindly pls help me.
Your tutorial series are very helpful for beginners. Thanks so much. Hope you keep your passion.
Thanks a lot for the wishes Nguyen
Hi Raghav, the way you are zooming on some important areas while showing the process,it’s great. Very helpful. Will it be possible for you to create one video on Appium interview questions and answers please? It will be great help.
Thank you for your hardwork and all the efforts for the video!
Yes, definitely I will do Mukta
Just amazing as always...
May Allah give you best reward.
Thanks a lot for you for your kind helps...
Allah has created some people to make the people's life easy and you are definitely one of them.
You are the super talented, you know how to make the things easy..
So nice of you Md Shah
Watched a lot of your videos and now came back to comment here.
Your videos are the best. I am glad I found your channel.
Thanks Karthik. I am humbled
Wow, another great video, thank you! You're like a human encyclopedia. 😄
So nice of you. Humbled
Please try to remove the background noise. It's really annoying otherwise the tutorial is really good. :)
Hi Vikas, I noticed it comes for 10 sec at around 3:20. Not sure how was it introduced.Will improve on the audio.
@@RaghavPal Were you getting a phone call?
UI automator viewer shows blank screen of my android. What can be the problem?
Hi, may be the sdk is not compatible. Check stackoverflow.com/questions/35124197/uiautomator-viewer-of-android-sdk-returns-blank-screenshot
And all your tutorial are very helpful and I learned a lot from each n every tutorial...Very easy to understand
Glad to hear that Neha
Thank you for having so many exciting videos.
Glad you like them Mike
I get: "C:\Windows\system32>uiautomatorviewer
-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit."
I researched the problem and you have to edit .bash_profile and that seems tough, so I will just use the Appium selector option.
Hi, What is your java ver.
You can check on cmd with command
java -version.
uiautomatorviewer and sdkmanager.bat usually works well with java 8
Or you can try getting sdk tools from
androidsdkmanager.azurewebsites.net/SDKTools
Also check this
stackoverflow.com/questions/46402772/failed-to-install-android-sdk-java-lang-noclassdeffounderror-javax-xml-bind-a
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
Excellent learning
Thanks a lot Giri
Hello Raghav,
Your sessions are really usefull. Is it mandatory to install andriod SDK?
Yes, we need Android SDK with appium
I just get "Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema" when I try to run SDKmanager.bat and error "-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit." when I try to run UIAutomatorViewer.bat in cmd. JAVA_HOME is pointing at "C:\Program Files\Java\jdk-13.0.1"
Hi, What is your java ver. You can check on cmd with command
java -version.
uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/46402772/failed-to-install-android-sdk-java-lang-noclassdeffounderror-javax-xml-bind-a
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
@@RaghavPal Hi. It's 13.0.1 for jdk-13.0.1, and jre1.8.0_191, thanks. I should mention that I'm trying to get this to work with Android Studio instead of downloading files separately. I have installed API version I need for my phone. My phone is showing up correctly when I run "adb devices".
Okay, can you try with java 8 as mentioned in the links and lets see if we get some diff output
Hello Raghav, I'm getting "Exception in thread "main" java.lang.NullPointerException"
I am very grateful for your tutorials
Hi Julio, thanks, Pls check the detailed logs. Search for caused by section in logs. It will help in troubleshooting
Awesome sir
Thanks
Hi Raghav, do we need to install Android Studio, to get Uiautomaterviewer. Becuase, with sdkmanager cmdline-tools I couldn't see uiautomatorviewer in tools/bin?
You can, if you do not get it the other way
Hi Raghav, you mentioned that you thought how to connect a real android device through WIFI in 5&6th video. but you didn't thought how to connect through WIFI(could you please provide the link how to connect through WIFI) and you're classes are very very helpful, I owe for you
Hi Vishnu, Pls check czcams.com/play/PLhW3qG5bs-L8npSSZD6aWdYFQ96OEduhk.html
Hi Raghav,
Thanks for the detailed session.
Im facing an issue here. When I open the uiautomatorviewer and try to take the screenshot dump, I'm seeing an error popup.
"Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!".
I went through stackoverflow and other forums and tried few steps mentioned, but did not resolve the issue. I'm always seeing this. Could you please help.
Note: I'm connected to a real device, Appium server is not running.
Hi Jisha, Is this for a specific application, did you try with a diff app or device
@@RaghavPal Hi Raghav, Not for specific app. I tried for a simple calculator app on my phone.
Can try with a diff app
@@RaghavPal I'm having the same issue across any app. I noticed the SDK tools folder is different now from Android Studios - could that be the issue?
Hi Jisha..I was facing same issue ..Rebooting phone worked for me :)
Grande papa
Hope this was helpful
This tutorial helped me a lot but I have one question. Whenever I click the uiautimatorviewer, the cmd just open for a while then close on its own. I also tried the other method which is typing cmd on the folder address but I keep getting this error: Cannot load 64 bit SWT libraries on 32-bit JVM. By the way, I'm using eclipse on mobile automation. Thanks in advance!
Hi, what is your java ver. Some users found it works well with Java 8
Now I face the same problem! I am using Java 11:(
Raghav how could i scroll usin appium i tried
ITouchAction t = (ITouchAction)new TouchActions(Driver);
and the error:
The IWebDriver object must implement or wrap a driver that implements IHasTouchScreen
Hi Andre, driver should be passed as IPerformsTouchActions stackoverflow.com/questions/30909818/the-iwebdriver-object-must-implement-or-wrap-a-driver-that-implements-ihastouchs
stackoverflow.com/questions/46550497/how-to-scroll-down-to-click-the-element-in-android-using-appium-and-java
@@RaghavPal wasn't work for me
I used sendkeys instead and it worked 👍
watched all 9
great Rashad
Hi Raghav, What if we are using simulator instead of actual device. Can you share the video to connect to simulator and then Appium Desktop or UI Automator
Hi Bhushan, I will plan for that
UIautomator.bat file is missing in my sdk package. Could you please help. TIA
Hi Sangavi, These user comments will help
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/android/repository/sdk-tools-windows-3859397.zip
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
Hi Raghav this is another way to inspect the elements isnt it? Do you recommend uiautomator against appium desktop to inspect? Cause i am using appium desktop nowadays
Both are good, uiautomatorviewer is a standard UI tool shipped as part of Android Studio for analyzing those UI components of your Android application. it is an inspector tool provided by Google that provides similar functionality to the Appium inspector tool
So UIAutomatorViewer is designed mainly to save screenshots(files) and use them without the need to plug in the device, right?
Hi Mr. S.H.,
UI Automator Viewer is a tool provided by Android SDK which allows the user to inspect the UI elements of an Android application. It is mainly used for locating the UI elements on an Android app so that Appium can interact with them during automation testing.
UI Automator Viewer can be used to capture screenshots of the UI elements of an Android application, which can be useful for debugging or troubleshooting purposes. However, it is not primarily designed for saving screenshots and using them without plugging in the device.
Hi Raghav,
That was an interesting session. Can we you UI Automator to locate elements from Webpage by connecting our real device?
Hi Sriharsha, yes you can
Hi! Thank you so much!!! Great tutorial!! 😀. Just one quick question, Do we have available any tool that similarly Chropath enables us to test if the Xpath that we have created is finding the right element (Highlighting it)? Greetings from Argentina!
Hi Mariano, can check selectors hub
really useful bro.thanks for d video
Most welcome Mathivanan
Raghav, I have downloaded the command line tools zip file. After unzipping I didn't find the uiautomatorviewer.bat file, Kindly help.
Hi Yogesh, what is your java ver. Can check this - stackoverflow.com/questions/46908523/uiautomatorviewer-batch-file-is-not-opening/51237395
@@RaghavPal Hi, Raghav, I have downloaded the latest command-line zip file from developer.android.com/studio , "commandlinetools-win-6200805_latest.zip". After unzipping, the tools folder doesn't contain UIAutomatorViewer. FYI: I have java version-1.8.0_161
@@@RaghavPal
I also tried the same thing by downloading the latest cmdlinezip file but no change.I am not able to see uiautomatorviewer.bat file in bin
Hi, Thanks for this informative video. I have a query, which app you are using to show the mobile execution...?
Hi Abhijit, I am using Vysor
legend
You are the best and you always make me look good at work because of you educational videos. Thank you
Most welcome Mzamo
Starts from 3:00.
Thanks for adding
Are we able to save images/videos using UIAutomatorViewer? For example if the app I was browsing instead was Twitter instead of calculator, all the elements for the Twitter would show up... including the png/mp4 right?
Yes
great job sr
You're welcome Ankit
hello..In my app, there is no id,no text..only index is mentioned. How can we locate the element?
Hi Aishwarya,
In Appium, you can locate elements using various methods such as XPath, class name, accessibility id, etc. In your case, since the only attribute available is the index, you can use the index locator strategy to locate the element.
Here's an example code snippet in JavaScript:
// assuming driver is your Appium driver instance
const element = await driver.findElement('android=new UiSelector().index(2)');
In the above code snippet, we are using the android locator strategy since the app is an Android app. If it's an iOS app, you can use the ios locator strategy instead. The UiSelector().index(2) will locate the element based on its index value.
You can also use the driver.findElements() method to locate multiple elements based on their index values. For example:
const elements = await driver.findElements('android=new UiSelector().index(2)');
This will return an array of elements that have an index of 2.
Note that using the index locator strategy can be less reliable compared to using other attributes such as ids or accessibility ids. If possible, try to work with the app developers to add unique identifiers to the elements for easier and more reliable automation.
which is better, Appium Desktop Inspector or UIAutomatorViewer ? please explain the pros and cons
Hi both are good and have similar backend, See whats easier for you
Hi Raghav, uiautomatorviewer is launched but I am unable to capture screenshorts, no action is performed on uiautomatorviewer can you please help??
Hi Sunny, pls check if the appium server is running, if yes, try to stop and try again
Hi sir, I am unable to view UI Automator viewer after installing android studio and environment variable setup, getting error like C:\Users\Admin\AppData\Local\Android\Sdk\tools\bin>uiautomatorviewer.bat
Error: Could not find or load main class com.android.uiautomator.UiAutomatorViewer
Caused by: java.lang.ClassNotFoundException: com.android.uiautomator.UiAutomatorViewer
C:\Users\Admin\AppData\Local\Android\Sdk\tools\bin>
Please suggest me how to evaluate this issue?
Lakshmi
It seems you're encountering an issue with running UiAutomatorViewer in Android Studio. Let's troubleshoot this! Here are some steps you can follow:
1. Check Java Version:
- Ensure that you have Java 8 installed. UiAutomatorViewer might not work with newer Java versions.
- If you're using a different version, consider downgrading to Java 8¹.
2. Set JAVA_HOME Environment Variable:
- Make sure you've set the `JAVA_HOME` environment variable to point to your Java 8 installation directory (e.g., `C:\Program Files\Java\jdk1.8.0_311`).
- You can add it in your system or user environment variables³.
3. Run UiAutomatorViewer:
- Open a command prompt (cmd) as an administrator.
- Navigate to the `tools/bin` directory inside your Android SDK folder (e.g., `C:\Users\Admin\AppData\Local\Android\Sdk\tools\bin`).
- Execute the command: `uiautomatorviewer.bat`.
Hopefully, following these steps will resolve the issue
-
Basically, the class name is a attribute/locator right? but you have used it as a tag name.
This is how we use for Xpath: //TagName[@Attribute=Value], can we use as you mentioned also?
Yes, Ashok, If you need more help with XPath can watch this - czcams.com/play/PLhW3qG5bs-L83gLEZVIDHOvgTTz27po_0.html
I can not click "back " button . It is not part of Ui. How can I go back?
Ozlem
If you're unable to click the "back" button using UI Automator Viewer because it's not directly detected as a UI element, you can still navigate back in the app using alternative methods. Here are a couple of approaches you can try:
1. **Simulate Swipe Gesture:** You can simulate a swipe gesture from right to left on the screen to navigate back. Use the `UiDevice` class to perform the swipe gesture. For instance:
```java
UiDevice device = UiDevice.getInstance();
device.swipe(device.getDisplayWidth() * 0.8f, device.getDisplayHeight() * 0.5f, device.getDisplayWidth() * 0.2f, device.getDisplayHeight() * 0.5f, 500);
```
2. **Use KeyEvent:** You can simulate pressing the "back" button using the `KeyEvent` class. For example:
```java
Runtime.getRuntime().exec("/system/bin/input keyevent 4");
```
Before attempting these methods, ensure that your UI Automator script has successfully connected to the device and the app is running in the foreground.
Hello Raghav, i have created a calculator project. Whenever i try to run my project, it launches the Calculator app in emulator but its not performing the events like clicking on 2 and plus symbol. How to share the screenshot of error which i am getting ?
Hi Rahul, you will need to check the detailed logs and troubleshoot. If you still cannot resolve it. Then message me with the steps you have tried.
Hi Raghav, i couldn't fine uiautomator.bat file in my bin folder can you help me with that?
Hi, These user comments will help
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/android/repository/sdk-tools-windows-3859397.zip
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
Hi I am not able to open UIAUtomator tool from cmd as well as from bin folder. It is giving me error "-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.". My jdk version is 15.0.2, Android Studio Version 4.1, Appium v 1.19.1
Hi Veena, As per most users comments, it worked well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
Hi Raghav, I am getting below error message pop-up while taking the screenshot using uiautomatorviewer.
"Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
"
I have check my device is connect: using adb devices.
Hi Kapil try to restart server again. Check this - stackoverflow.com/questions/40214342/error-obtaining-ui-hierarchy-error-while-obtaining-ui-hierarchy-xml-file-com-an
Thank you for a nice tutorial. Is it possible to get layout inspection without direct interaction with layout? I mean if we run a test case from eclipse or android studio then is it possible to get automated layout inspection alongside each step of test case being played on a device? Can I get this with any other mobile testing tool? Any guidance will be highly appreciated!
Hi Saba,
You can try TestProject - czcams.com/play/PLhW3qG5bs-L_QuqpGY-B-1ifP1j4ve3fx.html
Thanks,
Raghav
you are legend
So happy and humbled to see this Le Minh
Hi Raghav,
When I open the uiautomatorviewer file in the terminal on mac getting this error:
Could not find or load main class com.android.uiautomator.UiautomatorViewer, I have set all the paths SDK, platform-tools and have installed java. Please help me how to fix this.
Hi Sandhya, can check this stackoverflow.com/questions/40718487/error-could-not-find-or-load-main-class-com-android-uiautomator-uiautomatorview
Hi Raghav, thanks for this course. i am getting the following error while running uiautomatorviewer.bat, I don't know how to fix and continue further, Do you know why i am getting this error?
C:\Users\AppData\Local\Android\Sdk\tools\bin>uiautomatorviewer.bat
-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Hi Mathi, this can help stackoverflow.com/questions/18459945/how-to-solve-could-not-create-the-virtual-machine-error-of-java-virtual-machine
Hi Raghav,
I am using macOS for iOS mobile development.
I can't open the UIAutomatorViewer. I am using the simulator of Xcode and I can't use the 'uiautomatorviewer' on my terminal.
It only display: -bash: uiautomatorviewer: command not found
Can you help me out? Thanks.
Hi Shiela, Pls check if the installation was proper. Can try reinstalling OR for iOS you can check this discuss.appium.io/t/what-are-the-best-tools-to-find-element-locators-for-ios-apps/4509
kobiton.com/book/chapter-6-walkthrough-of-uiautomator-for-android-and-accessibility-inspector-for-ios-for-element-extraction-2/
Hi Raghav, could you please make a video on how to locate elements in web view in native app?
Hi Ajay, will plan to make it
@@RaghavPal thanks 👍🏻..will be waiting for it
@@RaghavPal Do you have a video for this now?
Hi Raghav sir,
i am not able to click on login button application show error message
Element info: {Using=id, value=com.pixilapps.selfcare:id/btn_skip}
null please help me
Hi Mayur, try to use some other locator for this
C:\Users\SPURGE\AppData\Local\Android\Sdk\tools\bin>uiautomatorviewer.bat
-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This error i am getting while executing uiautomatorviewer.bat on cmd prompt
what do to resolve it?
Hi Jayesh, Hi, What is your java ver.
You can check on cmd with command
java -version.
uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/46402772/failed-to-install-android-sdk-java-lang-noclassdeffounderror-javax-xml-bind-a
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
Appium inspector already supports this then why we need uiautomater ?
Siddharth
Let's break down the question and provide a step-by-step explanation.
Step 1: Understand Appium Inspector
Appium Inspector is a tool provided by Appium, an open-source test automation framework, to inspect and identify UI elements of mobile applications. It allows users to:
* Launch the application on a mobile device or emulator
* Inspect the application's UI elements, such as buttons, text fields, and labels
* Get the properties and attributes of these elements, like their XPath, ID, or class name
* Use this information to write automation tests
Step 2: Understand UiAutomator
UiAutomator is a testing framework provided by Google for Android devices. It allows users to write automated tests for Android applications using Java or Python. UiAutomator provides a way to interact with the device's UI, such as:
* Performing actions like clicks, swipes, and long presses
* Verifying the existence and properties of UI elements
* Automating user interactions and testing application functionality
Step 3: Identify the differences between Appium Inspector and UiAutomator
While both tools are used for mobile automation testing, they serve different purposes:
* Appium Inspector is primarily used for element inspection and identification, whereas UiAutomator is a full-fledged testing framework for automating user interactions and testing application functionality.
* Appium Inspector supports multiple platforms, including iOS and Android, whereas UiAutomator is specific to Android devices.
* Appium Inspector is part of the Appium ecosystem, which provides a unified testing framework across multiple platforms, whereas UiAutomator is a native Android testing framework.
Step 4: Answer the question
So, why do we need UiAutomator if Appium Inspector already supports element inspection?
The answer lies in the differences mentioned above. While Appium Inspector provides a convenient way to inspect and identify UI elements, it is not a full-fledged testing framework like UiAutomator. UiAutomator offers more advanced features for automating user interactions and testing application functionality, which are not available in Appium Inspector.
Additionally, UiAutomator is a native Android testing framework, which provides better performance and more precise control over Android-specific features and APIs. Appium Inspector, on the other hand, is a cross-platform tool that may not provide the same level of native integration and performance on Android devices.
--
Hi Raghav ,
I have downloaded platform tools and other sdk data from Android studio but i didn't get tools folder in it .
Although my automation is running Fine but it takes too time to launch.
I also tried to download from command line zip folder in which also tools folde is missing
Hi Praveen, try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
Hi Raghav,
I'm getting the following error
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
1. My appium server is off.
2. Restarted adb
3. Restarted emulator many times.
No remedy.
Please help!!
Hi Manoj, pls check if this helps - stackoverflow.com/questions/40214342/error-obtaining-ui-hierarchy-error-while-obtaining-ui-hierarchy-xml-file-com-an
Hey sir,
I m getting an error org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.while using all the parameters so for that what I will do now? Used for my particular app, not for calculator
Hi Pooja, you can try adding some wait time, Also ensure the object locators are provided correctly
Hello, Raghav bro. We have owned the android application. in that App, the Elements was not locating while running the script. Actually, i tried in many ways like xpath, id and name also for the particular element. but, the Action not worked when run the script. Calculator app was working fine. in same way I tried in our Owned App which is not working. executed in "appium desktop inpector" and "uiautomator". Please help me with this...!
Hi Asarudeen, will need to check the details and logs, Can try some other example online
Facing some issue to open ui automator viewer. when I try to open ui automator by double click uiautomatorviewer.bat
File or also tried to open with cmd but in both cases my ui automator viewer not open.
Please help.
Note: my physical device successfully appear in cmd. Means device connected with laptop.
Hi, this can help stackoverflow.com/questions/49199331/ui-automater-viwer-is-not-opening
Hi Raghav, how to handle the element or know the object/elements involved if the app was using a WebView or using a Hybrid? .
Hi Christopher, wil need to check more on this online. This may help -
discuss.appium.io/t/how-to-identify-webview-elements-in-android-hybrid-app/5140/3
Hi Raghav,
I have connected my mobile phone it is showing in vysor as well as on cmd when i type adb devices.
But when i open the UIAutomatorViewer by clicking on the batch file and after it gets opened when i click on the device screenshot button it gives me an error saying " unable to connect to adb. check if adb is installed correctly"
Can you help me in this?
Hi Sai, check if this helps stackoverflow.com/questions/27734121/unable-to-connect-to-adb-check-if-adb-is-installed-correctly
@@RaghavPal Thank you so much Raghav everything is working fine now.Thanks for the information
sir.. if im trying to uiautomator and try to click on device screenshot option im getting this below error. please tell me what is the solution for this.
"Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!]"
Hi Shiva, is your appium server running. Try to stop it and try again. Also restart adb server
sudo adb kill-serversudo adb start-server
Hi Raghav - I am getting the following error while loading the device in UIautomator
"Error obtaining UI hierarchy
Reason:
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!" It might be becuase of old version of uiautomator ..I tried installing uiautomator2.But I am not able to install it..Can you please guide me for this issue?
Hi Neha, reload your screen again stackoverflow.com/questions/40214342/error-obtaining-ui-hierarchy-error-while-obtaining-ui-hierarchy-xml-file-com-an
Hi Raghav. Need your help please on this.
I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac
Hi Kedar, will need to check the error details, ensure that appium server is not running on the same port and the device is connected
@@RaghavPal Thanks so very much Raghav for your reply. The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231.
I need to connect uiautomatorviewer with Memu Play emulator, but I can't. Would you give me any advice?
From already thank you very much.
Yago
To connect uiautomatorviewer with Memu Play emulator, you can follow these steps:
1. *Install the Memu Play emulator.*
2. *Install uiautomatorviewer.*
3. *Connect your Memu Play emulator to your computer using USB.*
4. *Start the Memu Play emulator.*
5. *Open uiautomatorviewer.*
6. *In the uiautomatorviewer toolbar, click the "Window" menu and select "Devices."*
7. *In the "Devices" window, select your Memu Play emulator and click the "Connect" button.*
*Troubleshooting:*
* If you are unable to connect to your Memu Play emulator, try the following:
* Make sure that your Memu Play emulator is running.
* Make sure that your computer is connected to the internet.
* Try restarting your computer and the Memu Play emulator.
* Try connecting to your Memu Play emulator using a different USB cable.
* If you are still unable to connect to your Memu Play emulator, you can try using the following command:
```
adb connect localhost:5555
```
*Note:* You will need to have the Android SDK installed on your computer to use this command.
Once you are connected to your Memu Play emulator, you can use uiautomatorviewer to inspect the UI elements of your app and automate actions.
Sir, it seems like the uiautimator viewer bat file is not inculded in the latest version of sdk manager. Are there any alternatives for this or can I ask for a copy for the .bat file, I really wanna learn how to automate.
This user comment can help:
These user comments will help
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/android/repository/sdk-tools-windows-3859397.zip
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
thanks
You're welcome Jones
Hi Raghav i cant see the ui automatorviewer run.bat
Hi Abhi, These user comments will help
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/android/repository/sdk-tools-windows-3859397.zip
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
hi Raghav, I am facing issue with the following error regarding uiautomator , tried many ways but no solved with the issue please help me out!!
Error while obtaining UI hierarchy XML file: com.android.ddmlib.SyncException: Remote object doesn't exist!
Pls check this stackoverflow.com/questions/25201743/error-in-using-uiautomatorviewer-for-testing-android-app-in-appium
@@RaghavPal issue not resolved yet
In case I get any more info, will share with you
HI Raghav very good video can you create one video android studio app how to run appium
Sure, I will plan
Hi Raghav,
I am getting an error in UI automator viewer saying "unable to connect to adb" in cmd prompt I can see that my device is attached..
Please help
Hi Syed, pls check this stackoverflow.com/questions/27734121/unable-to-connect-to-adb-check-if-adb-is-installed-correctly?rq=1
Can also check this
Step 1: You know where your android-sdk is installed in your system if you didnt changed the location search in ProgramFiles/Android
Step 2: close eclipse.
Step 3: Copy adb.exe in android-sdk/platform-tools/ folder
Step 4: Paste that adb.exe in android-sdk/tools/ folder
Step 5: Now open eclipse go to Windows --> Preferences choose android then click browse and select android-sdk with in few minutes
stackoverflow.com/questions/6361349/android-problem-eclipse-cannot-find-adb-exe
@@RaghavPal But i m unable to see the Android option in the Windows->preferences section
I have updated sdk file and in the latest sdk, uiautomator is missing
is there an any alternative of the this? or am I missing something here
Hi Ashish, try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
Hello Sir.
If we connect our mobile with laptop, is there any possibility of some virus coming into the mobile from the laptop.?
Hi Krishna, we cannot rule out the possibility, Just have good anti-virus softwares installed. Also it is recommended to use device that you do not use for your primary use
can you pleace make a video on appium python using pycharm for android
I will plan on this Gowtham
How about using typescript? Do you also have video's for it?
Not yet Yasin
Hi, I am getting this error while running "uiautomatorviewer" command:
Djava.ext.dirs=/Users/yamini/Library/Android/sdk/tools/lib/x86_64:/Users/yamini/Library/Android/sdk/tools/lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Hi Yamini, What is your java ver.
You can check on cmd with command
java -version.
uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/46402772/failed-to-install-android-sdk-java-lang-noclassdeffounderror-javax-xml-bind-a
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
@@RaghavPal Hi Raghav, Thanks for your reply. I checked and my java version is "11.0.2". I don't want to downgrade my java. Is it possible to use multiple java versions for different software?
Hi Yamini, For Java 11 Reference: stackoverflow.com/questions/60440509/android-command-line-tools-sdkmanager-always-shows-warning-could-not-create-se
1. Download latest Command line tools from android i.e. commandlinetools-win-6200805_latest.zip
2. Unzip the downloaded file
3. Create directory for storing commandline tools somewhere on your disk, with following path included: android/cmdline-tools/latest. Basically when You unzip this Cmd line tools, just rename tools directory to latest and make sure You put this latest folder in android/cmdline-tools directory somewhere on your disk
4. Create ANDROID_HOME environment variable for directory that stores the cmdline tools directory location like: C:\YourLocationWhereYouStoreTheDirectory\android\cmdline-tools\latest
5. Create new entry in Path environment variable as %ANDROID_HOME%\bin
Also check other comments
Hiii raghav my usb cable connected device is not showing in list of devices (redmi 4)
Hi Ravi, pls check
1. Dev mode enabled on Device
2. USB debugging is on on Device
3. Check your java version
java -v
I have child with java 8
UIAutomator viewer .bat file is not found in latest version.Can you pls say, is there any other solution for finding the locators?sir
Hi Lokesh, you can also use Appium Desktop Inspector
Hi while running the uiautomatorviewer.bat file I get the below error. I am using jdk 15.0.2. I set all the paths but still getting below error. Please help me
-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Hi Pooja, What is your java ver.
You can check on cmd with command
java -version.
uiautomatorviewer and sdkmanager.bat usually works well with java 8
Also check this:
stackoverflow.com/questions/46402772/failed-to-install-android-sdk-java-lang-noclassdeffounderror-javax-xml-bind-a
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
@@RaghavPal i am using 15.0.2 java is there any other way to open the uiautomatorviewer.
will need to check on this
@@RaghavPal ok sure if u get the solution just let me know
Hello Raghav, can you suggest how to change the image orientation in Uiautomatorviewer , mine is gaming application. I am looking for landscape mode instead of portrait mode.
Hi Pokuri, I have not tried myself but you can change screen orientation while testing with appium - appium.io/docs/en/commands/session/orientation/set-orientation/
Thanks Raghav for your quick response.
Hi Raghav, where can I find this UI Automator Viewer? I downloaded the command line tool for Windows and installed it properly. But I cannot find the UI Automator Viewer tool in the folder
Hi Christopher, not sure if something has changed. Will need to check online
@@RaghavPal Yes, it is changed. Kindly update.
@@theriderpanda Hi, How does it work now? I don´t have automator viewer in my folder.
@@RaghavPal Sir i am facing the same issue. UI Automator Viewer.bat file is missing in the latest android sdk folder(i.e Android-sdk/tools/bin). please help where to find it.
commandlinetools-win-6609375_latest.zip
I am also facing same issue, please can some help me ASAP
Hi Raghav,
I am getting below error while taking the "Device screenshot"
Error obtaining UI hierarchy
Error taking device screenshot: EOF
Could you please help me on this?
Keep on trying you will get it, even I faced it. Restart uiautomatviewer, try again like 5-8 times.
And make sure device is connected and appium server is not running
Thanks for adding your inputs Love & QABABU.COM
I'm still getting this error. How did you fix it?
Iam getting error Exception in thread main.java.lang.unsupportedclassversion mejor: minor version 52 when I open uiautomatorviewer please suggest me solution.
Hi Shyam,
The error "Exception in thread main.java.lang.unsupportedclassversion: mejor: minor version 52" occurs when you are trying to run a Java class that was compiled with a newer version of the Java SDK than the version you have installed on your machine
Here are a few things you can try to fix the issue:
Make sure you have the latest version of Java installed on your machine
Check the version of java installed on your machine and update it if necessary
Check the version of java that the Uiautomatorviewer is compiled with, it should be compatible with the version you have installed on your machine
Make sure that the JAVA_HOME environment variable is set to the correct Java SDK installation folder
Try to run the command with the latest version of java. e.g. java -jar uiautomatorviewer.jar
Try to run the command by specifying the path of the Java executable. e.g. "path-to-java\bin\java.exe" -jar uiautomatorviewer.jar
Try to re-install the Uiautomatorviewer and ensure that you have the latest version of the software.
Check the compatibility of Uiautomatorviewer with your operating system, some version of Uiautomatorviewer may not work properly on your operating system
Thank you ,
I was trying slove this exception last 3 month but i couldn't slove now it's working 😀🙏
when i type uiautomatorviewer.bat by cmd then i faced this issue plz help me?
-Djava.ext.dirs=..\lib\x86_64;..\lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Hi Akaash, what is your java version, You can try 2 things
1. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
2. Use Java 8 and try again
@@RaghavPal I am having the same problem , my jdk version is jdk-14.0.2 and I have updated android sdk build tools from 26 and above from sdk manager along with updating sdk platforms . I am still getting the same error when I type uiautomatorviewer.bat in command prompt. If I do it from the tools section, uiautomatorviewer.bat will open a blank cmd and close it withinn a sec.
C:\Android_sdk\sdk\tools> uiautomatorviewer.bat
-Djava.ext.dirs=lib\x86_64;lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Please tell how do I start UIautomatorviewer in linux....I can't run that file ( I have also run chmod command )
Hi Rudraksh, what is the error you are getting Pls see if this helps - stackoverflow.com/questions/18658322/unable-to-start-uiautomatorviewer
resource-id is missing in my project...
how can I find it?
Hi Julia, it may be that dev team or framework did not add it. You can ask to the dev team or check other properties that can uniquely identify the element
Hi Raghav I am using selenium 4.1.1 version and appium driver in my framework and driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Rahul \"));"); is not working it is giving message " The method findElementByAndroidUIAutomator(String) is undefined for the type AppiumDriver" plaese suggest how to solve this.
Hi Rahul, pls check this - stackoverflow.com/questions/56710457/cannot-find-findelementbyandroiduiautomator-method-for-appium-android-driver
@@RaghavPal Hi Raghav Thanks for the response. I followed the link and this doesn't solve the problem with selenium 4.1 and java client 8.0.0 beta 2 . It seems TouchAction is deprecated. Any suggestions how to do scrolling or other action in mobile automation.
Uiautomator.bat is not available for me
Hi Pavithra, I am listing all user comments related to UIAutomator.
These user comments will help
1. i had uiautomatorviewer.bat inside tools folder instead of tools/bin
2. try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
3. can also use Appium Desktop Inspector instead of uiautomator
4. In case appium server is running you can try after stopping appium and then open uiautomatorviewer
4. uiautomatorviewer and sdkmanager.bat usually works well with java 8
stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine
5. For windows download the zip file from this link ,extract and continue it works. because the current file that we are downloading does not contain all files and folders required. try this.
dl.google.com/android/repository/sdk-tools-windows-3859397.zip
6. I'm getting 'unexpected error while obtaining ui hierarchy' when tried to take screen-shot using uiautomatorviewer on Mac - The issue got resolved by downgrading jdk from 1.8.261 to 1.8.231
I am using commandlinetools(win-6858069) but there is no uiautomatorviewer.bat file inside cmdline-tools\bin. What to do ?
try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
@@RaghavPal I have downloaded both the SDK tools(version 25 and 26) but sdkmanager.bat does not seem to work may be due to some missing features (Java EE modules) in the latest java version. Is there any other solution that can work with the latest java version? Or may be any other solution of the real problem that is another app/trick that will work like uiautomatorviewer( appium inspector does not seem to work that finely ).
will check more on this
i had uiautomatorviewer.bat inside tools folder instead of tools/bin,
I tried and getting this error, can any one help.
Android\Sdk\tools\bin>sdkmanager "platform-tools" "platforms;android-29"
Error: Could not find or load main class com.android.sdklib.tool.sdkmanager.SdkManagerCli
Hi Murthy, try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
What app can i use to capture my phone behavior during mobile automation using real device?
vysor
Hi Raghav, thanks for all courses of your channel. Could you help me with this error, when I open the uiautomatorviewer and I click in Device Screenchot button, it always appears the error: Unexpected error while obtaining UI hierarchy
Hi Karlox...you need to disconnect and then again reconnect the adb device. Once the device gets connected it will work.
@@KajalKumari-qm2vu Hi Kajal, thanks for your answer but this hasn´t been the solution
Make sure appium server is not running or use diff ports. Also ensure your device is unlocked and usb debugging is enabled
@@RaghavPal. Thanks for the answer. I had an error, my android version is 10 and I was using sdkmanager "platform-tools" "platforms;android-28" instead of android-29. The error is solved.
@@KajalKumari-qm2vu Thanks for your answer. I had an error, my android version is 10 and I was using sdkmanager "platform-tools" "platforms;android-28" instead of android-29. The error is solved.
tools/bin not uiautomator present
Hi Rahul, pls check other comments on this video, can help
hi ragav, i have downloaded sdk-tools form the following link,
developer.android.com/studio
after unzipping i couldn't kind uiautomatoviewer in it. Can you please help me out in finding uiautomatorviewer
Hi Shiva, try getting sdk tools from androidsdkmanager.azurewebsites.net/SDKTools
Hello Again. I am getting an "NoSuchElementException" for Xpath, any comments??
HI Asif, you will have to troubleshoot and check some other locator that can work
Sir. I'm trying to automate an app. One of the option in app when I inspected in the UI automator it is showing as clickable =false. Cos of which my script is not clicking the option. Can you suggest me how to resolve it or how to click on that option.
Hi Shiva, have to tried with Appium desktop inspector. Check if you are getting same results.
@@RaghavPal yeah I tried with appium desktop inspector too.. since clickable=false, my script isn't clicking on the element. I guess I should use xy coordinates. But not sure how it is with appium. If you have any code snippet please share in the comments
Hi Shiva, as of now I do not have anything handy for this. Will have to get some online help
@@RaghavPal then make a video on this please.
I will do Shiva
can you do a video about installing older eclipse ide versions for java 8? I keep getting error that reads can't start java virtual machine or something similar.
I will check on this
@@RaghavPal please do. uiautomatorviewer only works with java 8, and I haven't been able to proceed any further cause I can't install eclipse that supports java 8 on my Mac.
okay, will update if I find more info
Error obtaining UI hierarchy
Reason: unexpected error while obtaining UI hierarchy.
Logs in cmd:- E/Screenshot: unsupported protocol: 2
Can anyone help in this? I did it for 7-8 times and every time i am facing the same issue. Appium server is running and i can see the devices in list as well(in cmd via adb devices).
My android version is 8.1.0
Hi Ashutosh, try after stopping appium server
@@RaghavPal i did that.. it's not working.. as of now i am using appium desktop inspector.
Ok you can continue with that for now.
How to deploy it on cloud and run against your phone in hand(ie not cloud device farm) via 4G without a pc or usb cable?
This can help czcams.com/video/uw1Inr1wAiA/video.html
@@RaghavPal this is via tcpip not over public internet. I don't have a laptop/PC. I want to connect from cloud host to my mobile.
I will check on this
@@RaghavPal one solution I found was to ssh into remote host from my mobile terminal and then do port forwarding. I don't have full clarity on that as I haven't been able to implement. Maybe if you could also research on these lines and make a video it will be great.