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


#5

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


#6

does clicking on text itself not work ?

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

if not i suggest dirty solution:

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

#7

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!


#8

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


#9

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.


#10

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);


Why is tap() deprecated?
#11

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);

#12

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


#13

@VolodymyrGlushkov
Hi, why don’t you use TouchAction.

TouchAction action = new TouchAction((MobileDriver) driver);
action.tap(x-cordinate,y-cordinate).perform();

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


#14

el should be WebElement


#15
public void tapSignUpLink() {
            WebElement element = driver.findElement(By.id("com.qwerty.android:id/label_need_account"));
            driver.tap(1, (element.getLocation().getX()+element.getSize().getWidth())*9/10, element.getCenter().getY(),200);
        }

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


#16

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.


#17

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


#18

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

        MobileElement someElement;
        someElement = (MobileElement) driver.findElement(MobileBy.id("test"));
        Point p = el.getCenter();

#19

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


#20

@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?


#21

Hi Aleksei!

How can i click on those links one by one as it doesn’t have any id’s
please help me how to resolve it.
Thanks in advance.


#22

@Prashanth try on same screen:

  1. switch to webview
  2. print “driver.getPageSource()”. publish it https://gist.github.com/ and give us a link

#24

@Prashanth if you use latest appium 1.6.5+ just log:

System.out.println(driver.getPageSource());

latest appium can switch to webView itself. if not i will show how to do it later…


#25

I am using 1.4.16.1 (Ohpiuchus) and i have windows 8.1 don’t have mac to upgrade to latest appium version