How can I access UiAutomator2Options
in Python with Appium v2.5.4?
I recently migrated to Appium v2.5.4 and Appium-Python-Client 4.0.0, but the usual import:
from appium.options.android import UiAutomator2Options
doesn’t work anymore. Instead, I see:
from appium.options.android import uiautomator2
How can I properly access and use uiautomator2options
in Python for my Appium setup?
Hey! I recently upgraded to Appium v2.5.4 too, and the way to access UiAutomator2Options
changed slightly.
Instead of importing the class directly, you now import the module and then access the class from it:
from appium.options.android import uiautomator2
options = uiautomator2.UiAutomator2Options()
options.platform_name = "Android"
options.device_name = "Pixel_3"
options.app = "/path/to/app.apk"
This worked for me after the migration. The class is still there, just under the uiautomator2
module.
I ran into the same thing.
Another way I’ve used it is importing the options class with an alias to keep things clean:
from appium.options.android.uiautomator2 import UiAutomator2Options
opts = UiAutomator2Options()
opts.platform_name = "Android"
opts.automation_name = "UiAutomator2"
It feels more explicit this way, and you can easily see that it’s specifically the UiAutomator2
options. I prefer this style when working on bigger projects.
From my experience, the simplest is just to follow the updated structure in the docs.
For example:
from appium.options.android import uiautomator2
from appium import webdriver
opts = uiautomator2.UiAutomator2Options()
opts.device_name = "emulator-5554"
opts.app = "/path/to/myapp.apk"
driver = webdriver.Remote("http://localhost:4723/wd/hub", opts)
This works perfectly with Appium 2.5.4, and you don’t have to worry about old import paths. I found it really streamlined the setup.