Search code examples
pythoniosappiumappium-iospython-appium

Detect location of specific text


Appium 1.5.0 
Xcode  7.3 
IOS 10.11.4 OSX EI Capitan
Using on:Simulator iOS 8.1

Suppose we have a text field To see more information clickhereand to get more click here.

So I identified the text using xpath and I can get its location and size. Now can we somehow get the location of here .I need to click it, but because it is not an element I cannot search for it. So somehow if I can get its location, I can tap at that.

But how can we get its location and still keep it generic so that it runs on different devices?


Solution

  • There isn't any direct way to achieve this(no API available in Appium itself). However, my solution is generic and will work on all devices(Android and iOS), all programming language implementation.

    1. [You have already done] get the location and size of the element.
    2. Take a screenshot of the current screen.
    3. Crop image from the screenshot using the location and size of the image.[This step can be skipped if there are not ambiguous targets]
    4. [You need to do this only one time manually] Crop out the image portion you want to get the location.
    5. Search the location of the cropped image, get the location and perform a precise tap/click.

    For image search refer here : How to find an image within another image using python