Selenium By and Appium AppiumBy
Selenium By and Appium AppiumBy
As an Appium and Selenium expert, I’ll explain these concepts in a beginner-friendly way.
Both Selenium By and AppiumBy are used to locate elements on an application so that automation scripts can interact with them (click, type, read text, etc.)
Selenium By
In Selenium, By is a class used to locate elements on web applications.
It tells Selenium how to find an element on a web page.
Why Selenium By is needed
- Web pages contain many elements (buttons, inputs, links, etc.).
- Selenium needs a clear rule to identify the correct element.
Byprovides different locator strategies to do this.
Common Selenium By locator methods
By.id()– Locate by HTML id attributeBy.name()– Locate by name attributeBy.className()– Locate by CSS classBy.tagName()– Locate by HTML tagBy.linkText()– Locate link using exact textBy.partialLinkText()– Locate link using partial textBy.cssSelector()– Locate using CSS selectorBy.xpath()– Locate using XPath
Selenium By is mainly designed for desktop and mobile web browsers.
Appium AppiumBy
AppiumBy is an Appium-specific locator class used to automate mobile applications
(Android and iOS), including both native apps and mobile web apps.
Why AppiumBy is needed
- Mobile apps do not use HTML like web apps.
- Mobile platforms expose elements using platform-specific attributes.
AppiumBysupports mobile-only locator strategies.
Common AppiumBy locator methods
AppiumBy.id()– Locate by resource-id (Android) or accessibility idAppiumBy.accessibilityId()– Locate using accessibility identifierAppiumBy.className()– Locate by UI classAppiumBy.xpath()– Locate using XPath (works for mobile too)AppiumBy.androidUIAutomator()– Android-specific locatorAppiumBy.iOSNsPredicateString()– iOS-specific locatorAppiumBy.iOSClassChain()– Faster iOS locator strategy
AppiumBy is optimized for mobile automation and understands
Android and iOS internals.
By and AppiumBy
| Aspect | Selenium By | AppiumBy |
|---|---|---|
| Primary Usage | Web application automation | Mobile application automation |
| Supported Platforms | Desktop and mobile web browsers | Android, iOS (native, hybrid, mobile web) |
| HTML Dependency | Works directly with HTML elements | Does not rely on HTML (uses mobile UI hierarchy) |
| Mobile-specific Locators | Not supported | Supported (UIAutomator, iOS predicates, class chain) |
| Accessibility ID Support | Not available | Available and recommended |
| XPath Support | Yes | Yes |
| Performance on Mobile | Limited and not optimized | Optimized for mobile automation |
| Package | org.openqa.selenium.By |
io.appium.java_client.AppiumBy |
Summary
- Use Selenium By for automating web applications.
- Use AppiumBy for automating mobile applications.
AppiumByextends the idea ofByto support mobile-specific locators.