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

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.

@Prashanth try on same screen:

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

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

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

you do not need mac :-). to install latest appium in windows you need:

  1. install nodeJS -> https://nodejs.org/en/
  2. in command prompt execute:
npm install -g [email protected]

although it’s beta - it has tons of improvements. if you doubt you can install previours like:

npm install -g [email protected]

now all is needed to start appium on windows PC is in command line execute “appium” :slight_smile:

Ok i will try it. and let you know.

it prints the page source as below how can i find elements to click on those links please help me.

<?xml version="1.0" encoding="UTF-8"?>

Hi VolodymyrGlushkov,
Can you please share me your code to click on Text link inside a TextView. Im facing similar kind of issue, i tried with below snippet. It doesnt work.

Element = Please click on the Our website using ‘Click here’
locator id = com.demoApp.sampleDemoApplication:id/text_title

*Click here has the link, which i need to click on from script.

Point point = element.getLocation();
size = getIOSDriver().manage().window().getSize();
int x = point.x + 1;
int y = point.y + element.getSize().getHeight() - 1;
TouchAction touchAction = new TouchAction(getIOSDriver());
touchAction.tap(x, y).perform();

Much appreciated for your response.
Thanks

How to do driver.tap ?
do I need to use touchActions?

@Priya_Khiwal tons of examples :- > https://github.com/appium/java-client/blob/master/src/test/java/io/appium/java_client/android/AndroidTouchTest.java

AndroidDriver, where does this come from? I am not able to resolve this dependency…

Right from java client -> https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/AppiumDriver.java

@Aleksei tap method could not be found using driver.tap and also referred the one which you had posted here still no luck.
Tried below code,
Getting error --> org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

Point center1 = driver.findElementById("new_order").getCenter();
TouchAction startStop = new TouchAction(driver)
            .tap(point(center1.x, center1.y))
            .tap(element(driver.findElementById("new_order"), 5, 5));//Getting error here
startStop.perform();

visit XYZ.com need to click. The entire TextView id is “new_order”
To place a new order, visit XYZ.com.
Screenshot:

removed first answer.

update code to something like:

        MobileElement el = (MobileElement) driver.findElementById("new_order");
        Point center = el.getCenter();
        TouchAction startStop = new TouchAction(driver)
                .tap(point(center.x + (el.getSize().width / 2) - 5, center.y)); // where -5 is to avoid el right border
        startStop.perform();

check that “el” will be found

@Aleksei Thanks it’s working on pixel 2 device1. i hope it will work on all device sizes.
And also two more question . 1.How did you calculate that it should be -5?
2. How to make it work when we have more than one clickable link like one mentioned by Prashanth

  1. you can replace -5 to some % as something in example of @mykola-mokhnach.
    • in mine example right part is: el.center.x + width / 2 - 5px.
    • in mykola’s: el.left.x + width * %. where % from 0 to 100%. i suggest use 90% (based on your screenshot)
  2. improve given tap example with giving not only X offset but Y offset also.

What if the clickable text is dynamic(sometimes first line and sometimes second line) and in the middle of string…How can we make it work?
Like, say Example: “place a new order, with XYZ.”