How can I click on Text link inside of TextView (Android)

Hello, can anyone help me?
I have an Spannable text in TextView: “You don’t have an account? Sign Up” And “Sign Up” is a link.
UIAutomator sees ID, Xpath, Name of whole string only, but not part of this string - text-link “Sign Up”.

How can I click on link inside TextView?
Was searching everywhere and still could not find solution. I need click on link inside of it. I’d like to find solution without using coordinates. It’s blocker issue for me =((

Added screenshot:

Can you please provide the screenshot of the page where you want to inspect the textview

Thanks for reminding! I’ve added a screenshot!

Is your app available on playstore or any other app similar to this UI. So that I can try from my side.

Not yet. It’s in develop wright now.
Same situation you can see in many apps with “Terms & Conditions and Privacy & Policy” sting.

does clicking on text itself not work ?

        ((AndroidDriver) driver).tap(1, driver.findElement("label_need_account")), 200);

if not i suggest dirty solution:

        MobileElement el = (MobileElement) driver.findElement("label_need_account"));
        ((AndroidDriver) driver).tap(1, el.getLocation().getX()+el.getSize().getWidth()-5, el.getLocation().getY() +5,200);

No, I don’t need to tap on whole element, only on part of it - “Sign Up”.
Unfortunately, there is only one way - Dirty solution ((
Thanks everyone!

May be you can use Index for finding the element with id.

All locators(resource-id, xpath, name, index, text… ) relates to whole Spannable Text: “You don’t have an account? Sign Up”.
Can’t find the way to tap only on “Sign Up” except of with coordinates. But this is not very good.

Found the Hard way for my case:

//give middle position with respect to height
int y_coodinate = (element.getLocation().getY() + element.getLocation().getY()+element.getSize().height) /2;

//give x - x/10 position with respect to width
int x_coodinate = element.getLocation().getX()+element.getSize().width - (element.getLocation().getX()+ element.getLocation().getX()+element.getSize().width)/10;

driver.tap(1, x_coodinate, y_coodinate, 1000);

sorry in advance but this is total mess :slight_smile:
one line of all your code

   driver.tap(1, (el.getLocation().getX()+el.getSize().getWidth())*9/10, el.getCenter().getY(),200);

Cannot resolve method ‘getCenter()’
Nope, it’s not working in one line. Maybe I need some extra Library for ‘getCenter()’ ?

Hi, why don’t you use TouchAction.

TouchAction action = new TouchAction((MobileDriver) driver);

You can get these by turn on Pointer location in your device developer settings

el should be WebElement

public void tapSignUpLink() {
            WebElement element = driver.findElement(""));
            driver.tap(1, (element.getLocation().getX()+element.getSize().getWidth())*9/10, element.getCenter().getY(),200);

Actual result:
“Cannot resolve method ‘getCenter()’”

Because, I don’t know how to get wright x-,y-coordinates of needed element. It should not be hardcore-digit coordinates. It should be some easy formula that works on most of devices with different display sizes.

Maybe I need another source of WebElement library for ‘getCenter()’ ?

i was wrong :frowning: it is MobileElement from Appium Java client.

        MobileElement someElement;
        someElement = (MobileElement) driver.findElement("test"));
        Point p = el.getCenter();
1 Like

Thanks! This way is really better! And it’s works!

@VolodymyrGlushkov I’m having similar issue… I need to tap on the link “Sign Up” which is part of below element
“You don’t have an account? Sign Up”.

My complication is that the label “Sign Up” can be on same line or it can be continue to the next line based on screen size.
rest of the label is not tappable

Basically, using x, y may not help… any suggestions on how we can workaround this?