Making Your Appium Tests Fast and Reliable, Part 4: Dealing With Unfindable Elements
One of the sad truisms of mobile testing is that we can & # x27; t invariably get what we want. The stack is so complex, the tools so nascent, that we are often in a view of get to try weird hacks just to get our test to work. Appium does everything it can to canonize the nigh reliable weird hack as official endpoint, so you can just go about your day writing straightforward Appium client codification. But sometimes, the world doesn & # x27; t cooperate. One common occurrent in this category is when an element is intelligibly visible on the screen, and yet can not be found. You & # x27; ve printed out the page germ. You & # x27; ve gone search in Appium Desktop, and sure enough, there & # x27; s no sign of the component! Why could this be? There are a number of reasons, but usually it has to do with how your app is developed. For iOS and Android, Appium is fundamentally at the mercifulness of the automation engines it progress on (XCUITest and UiAutomator2, respectively). These engines use the accessibility layer of the OS to determine which elements are available for mechanization. Oftentimes, apps which employ custom UI components have drop to register these custom components with the approachability service. This means that said element are essentially inconspicuous from the perspective of XCUITest/UiAutomator2, and hence un-automatable from the perspective of Appium. If this line your trouble, and if you hold the ability to vary the app beginning codification (or can convince someone else to), the solution is really pretty straightforward: simply become on availability for your custom UI controls! Both Apple and Google mention how in their Dr., but it & # x27; s easy to see why a developer might forget to do this, since it doesn & # x27; t affect the functionality of the app. Anyway, you can check out the proficiency at these tie: SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. If changing the app code isn & # x27; t an option, or if there is some other reason that your element is not findable (for example, React Native doing something goofy when you set your factor & # x27; s position toabsolute), you might need to pull out the big artillery. (Sorry, that sound wild: I should say, you might need to pull out the big keyboard! Because coding happens on keyboards!) Regardless of metaphor, what am I referring to? Tapping by coordinates. That & # x27; s correct: with Appium you can always tap the screen at any x/y position you like, and the tap will (/should) work. If the UI control you are targeting is underneath, the net result will be the same as having called afindElementcommand and so callingclick()on the result object. There & # x27; s a problem, though, which is that tapping by coordinate is notoriously brittle -- -hence why my suggestions on how to do it right are showing up here, in our series on test speed and dependableness. But maiden, why is tapping by coordinates brittle? For all the same reasons XPath is plausibly not a full locater strategy, and more One tantalizing solution would be to detect the constituentvisually, signification by comparison with a credit image. In fact, Appium can do this! But it & # x27; s pretty new and innovative, and will be the subject of a future Appium Pro edition once all the piece are firmly in place. In the meantime, a maiden pang at do tip at a coordinate more reliable would be to control our coordinate itself is dynamically calculated found on conditions. For example, if we know that our app renders in completely the same proportions across different screen sizing, we can lick the last problem in the list above by storing coordinates as percentages of screen breadth and tiptop in our code, kinda than storing actual x and y values. Then we determine the specific coordinates for a given test run only after making a call todriver.manage () .window () .getSize (), so we can become the percentages backwards into coordinates. This is a good starting, but it still doesn & # x27; t facilitate us in the event where the element might have move around for a variety of reason. Another idea is to chance the coordinates of your unfindable element via mention to an element whichis findable. The key insight of this tactic is that it & # x27; s frequently the example that the position of the coveted ingredient is always fixed in relationship to some early element, which may be base utilise the normalfindElementmethods. We can use the size and position of the citation element to calculate absolute coordinates for the desired element. Of course, you & # x27; ll have to discover your app & # x27; s pattern close to determine which features of the reference component are useful. For example, you might decide that the desired element is always 20 pixels to the right of the cite element. Or, it could be halfway between the right edge of the reference element and the right edge of the screen. Using a combination of the reference element & # x27; s bounds and the screen dimensions, pretty much any position for your desired element can be point dynamically and dependably. Let & # x27; s take a look at a concrete example usingThe App. Currently, the initial screen of The App looks like this: In reality, I can find all the elements I care about via Accessibility ID. But let & # x27; s act that the & quot; Login Screen & quot; list point is not approachable, and I can & # x27; t see it in the hierarchy at all. What I & # x27; m going to do is garner info about the element right below it (& quot; Clipboard Demo & quot;), and use that to tap the Login Screen element dead center. I will rely on the facts I know about my app, which is that & quot; Login Screen & quot; is a list point of the same dimensions as & quot; Clipboard Demo & quot;, and appears directly before it in the list. All I need to do, then, is find the centre of & quot; Clipboard Demo & quot;, and then subtract the height of the list item, and I & # x27; ll have the coordinate for the centre of & quot; Login Screen & quot;. Basic math, flop? So let & # x27; s have a face at the codification (which acquire we & # x27; ve gotdriver and wait objects all ready for us): This is a direct implementation of what I phrased in words above. The important command are of course the commands for getting the boundary of the quotation element(element.getRect ()), and the commands for setting up an AppiumTouchActionto natively tap on a coordinate. There are a few line responsible for this latter function, but they & # x27; re straightforward: press on a coordinate, wait for 500ms, and release. That & # x27; s it! Happily, this proficiency is cross-platform, so the above codification will run on both the iOS and Android versions of my app without limiting. And it is relatively robust and reliable. It will never be as reliable as tick on an ingredient found by Accessibility ID, of course, because in that case we have a guarantee of calling an underlying tap method on a platform-specific element reference. In most suit, that element reference will subsist even if the app is reorganized spatially. But if we are forced out into the cold dark, beyond all ability to find elements, then the technique discuss hither will help you at least retain a modicum of sanity. If you & # x27; re concerned in a runnable example showing the above code working on both iOS and Android, simplycheck out the codification for this edition! And check backwards presently for the up-to-the-minute in this mini-series on hurrying and reliability. Lead, Content Marketing, HeadSpin Inc. Piali is a dynamic and results-driven Content Marketing Specialist with 8+ eld of experience in crafting engage narratives and market collateral across diverse diligence. She excel in collaborating with cross-functional teams to acquire innovative content scheme and deliver compelling, authentic, and impactful content that resonate with target audiences and enhances brand genuineness. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts..png)



Making Your Appium Tests Fast and Reliable, Part 4: Dealing With Unfindable Elements
AI-Powered Key Takeaways
This article is the 4th in a multi-part series on test swiftness and reliability, invigorate by a webinar I afford on the same subject (you canwatch the webinar here). You might also want to check out,, and.

// first, find our cite constituent WebElement ref = wait .until (ExpectedConditions.presenceOfElementLocated (referenceElement)); // get the position and dimensions of the reference factor, and find its center point Rectangle rect = ref.getRect (); int refElMidX = rect.getX () + rect.getWidth () / 2; int refElMidY = rect.getY () + rect.getHeight () / 2; // set the midway point of our desired ingredient; we cognise it is one row above the // reference element so we simply have to deduct the height of the reference element int desiredElMidX = refElMidX; int desiredElMidY = refElMidY - rect.getHeight (); // perform the TouchAction that will tap the craved point TouchAction action = new TouchAction < > (driver); action.press (PointOption.point (desiredElMidX, desiredElMidY)); action.waitAction (WaitOptions.waitOptions (Duration.ofMillis (500))); action.release (); action.perform (); // finally, verify we made it to the login blind (which means we did so tap on // the desired element) wait.until (ExpectedConditions.presenceOfElementLocated (username));Piali Mazumdar
Making Your Appium Tests Fast and Reliable, Part 4: Dealing With Unfindable Elements
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence hardheaded usher for advanced exploiter (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence practical guidebook for advanced users (Part 4)
Discover how HeadSpin can empower your business with superior essay capabilities







Discover how HeadSpin can empower your concern with superior testing potentiality
Discover how HeadSpin can empower your business with superior testing capabilities
Connet Now


Automate This With SUSA
Test Your App Autonomously







.png)












