Using a Tap-By-Location Helper for Working With Unresponsive Elements
When I was work on a first-pass mechanization of a login stream for the Twitter Android app as portion of, I ran into an interesting problem, which is exemplify by the screenshot below. To get from the splash page to the login page, I needed to have Appium tap this & quot; Log in & quot; button. The only issue was, the button and the preceding text were all part of a individual element. I could find the ingredient, but when I used element.click () on it, nothing happened. At first, I thought this was one of those lawsuit where the component is not appropriately responding to the behavior of the click command. In such cases, it & # x27; s ofttimes useful to make use of something I call a & quot; tap by localisation & quot; helper. This is a small assistant method that makes it easy to tap an element using theActions API, alternatively of finding an element acknowledgment and calling element.click () as you normally would. Here & # x27; s the basic approach: Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. In code, it would look something like this, add to your base page object poser: Basically, we create a generic tapAtPoint method which handles turning a Point object into an Actions tap at that point. Then, we create the actual helper, tapElement, which does all the math for finding the midpoint of an element. To accomplish this it make use of the getRect method for WebElements, since that method revert to us both the X and Y location of the top-left corner of the element, and the property. To happen the midpoint, we just divide the width and height by 2, and add those amount to the X and Y values for the top-left corner, severally. Now, in our test codification, we can use the helper as follows (using an element from TheApp as an illustration): So I use this approach with the Twitter app, and thingsstilldidn & # x27; t work. What could be locomote on? Ultimately, I realized that it wasn & # x27; t enough to just tap the element containing the & # x27; Log in & # x27; text -- -I needed to tap that textbook specifically, still though it was all part of the like element as far as Appium was concerned. To make this possible, we would need to update our tapElement method, or more accurately, create a new helper method called tapElementAt. We take the ability to tap an component at an arbitrary distance from the top-left corner, and not just at the center. So here & # x27; s the set of helper methods we end up with when we make that addition and refactor: Now, tapElement becomes just a special case of tapElementAt, with hard-coded values for the element-relative localisation to tap. Notice that we are utilize relative percent values to pass into tapElementAt, rather than pixels. This makes it easy for us to eyeball the element regardless of screen size, and enter values that make sense. For the Twitter app above, I ended up compose the eq of: This yield a tap 90 % of the way from the left edge of the element (so only 10 % in from the correct edge), and 50 % downwards from the top (so right in the upright eye). And this did the trick! I recommend adding this kind of element tap helper to your framework for situations you see like this. And if you want to see these methods in action, psyche on over to theexample source codefor this edition. Lead, Content Marketing, HeadSpin Inc. Piali is a dynamical and results-driven Content Marketing Specialist with 8+ days of experience in crafting pursue narratives and market collateral across diverse industry. She excels in collaborate with cross-functional teams to acquire innovative substance strategies and deliver compelling, reliable, and impactful content that vibrate with quarry hearing and enhances brand authenticity. 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)



Using a Tap-By-Location Helper for Working With Unresponsive Elements
AI-Powered Key Takeaways

protected void tapAtPoint (Point point) {AppiumDriverWebElement el = driver.findElement (MobileBy.AccessibilityId (`` Login Screen '')); tapElement (el);protect void tapAtPoint (Point point) {AppiumDrivertapElementAt (el, 0.9, 0.5);Piali Mazumdar
Using a Tap-By-Location Helper for Working With Unresponsive Elements
4 Parts
-1280X720-Final-2.jpg)
Regression Intelligence practical guide for advanced users (Part 3)
-1280X720-Final-2.jpg)
Regression Intelligence practical guidebook for advanced users (Part 4)
Discover how HeadSpin can authorize your line with superior testing capabilities







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


Automate This With SUSA
Test Your App Autonomously







.png)












