Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's an efficient way to select an element by accessibility label in selenium-webdriver and appium?

I've just started auto end-to-end testing with my react native app, both ios and android, context is nodejs. Client is selenium-webdriver, which connects to appium server.

According to several sources, the best way to locate an element in React Native is to supply an accessibilityLabel to a View. However, in selenium-webdriver, there's no such function like:

driver.find_elements_by_accessibility_id('some id')

Currently I'm using a workaround instead:

driver.findElement(By.xpath('//*[@accessibilityLabel="some label"]'))

As it traverses all attributes of all elements, not hard to imagine its low efficiency. What could be a better approach?

P.S. I chose selenweb driveriver as client because it's also used for testing our web app, so I don't need to go through another learning curve. But if needed, I'm happy to switch to another client.

like image 999
Stanley Luo Avatar asked Jan 23 '26 00:01

Stanley Luo


1 Answers

You can do this with plain selenium webdriver like so:

driver.find_element("accessibility id", "some id")

That is basically all the helper method in the appium client is doing behind the scenes. It even works directly with WinAppDriver apart from Appium.

like image 144
keitwb Avatar answered Jan 24 '26 16:01

keitwb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!