Click on link inside TextView

Hello, anyone can help me how can I click on link inside TextView. Was searching everywhere and still could not find solution. I was trying this:
driver.findElement(By.xpath("//TextView[contains(text(),‘optimum.net/service’)]")).click()

But it only finds TextView element, but I need click on link inside of it

Can’t remember of any ‘pretty’ solution for this.

For that specific case you can use .getLocation() and .getSize() on the TextView element and do a tap using TouchAction on +/- left and bottom part of the element.

If you have several texts with the same automation need, then I guess the hardest solution is to build a class where you input text, font information and size of TextView and calculate where the link should be by distributing the text, exactly like app is doing.

Hope there are more answers, because I’m not thinking of any other way.

Thank you for reply. Of course this is one of the solution. I actually was looking for something that I can use on all devices(small and large screen). With this solution I have to do different test cases for different scale devices.
I was thinking may be there the way to click on element something like:
driver.findElement(By.id(“myID”)).driver.findElement(By.xpath("//text()=‘My text’ ")).click()

I know on the Web we can click on some specific text inside some id or xpath

May be there way in Appium as well?

The best solution i can think about here is to put in a list the last message and then to substring it in order to only have the link. after that, you will be able to press on the link since it will be on its own.
List list = …
String lastMsg = list.get(list.size() - 1).getText();
and then to substring lastMsg
this is the best i could find

How would that work?

The smallest element is android.widget.TextView. Unless dev team can change it and place the link in its own element, you will only be able to access the properties of the TextView only.

This is how I did, so far no other way to do that:

WebElement element = driver.findElement(By.id(txtSuppAppDescription));
Point point = element.getLocation();
int x = point.x +1;
int y = point.y + element.getSize().getHeight() - 1;
new TouchAction(driver).tap(x, y).perform();

The best solution i can think about here is to put in a list the last message and then to substring it in order to only have the link. after that, you will be able to press on the link since it will be on its own. List list = ..... String lastMsg = list.get(list.size() - 1).getText(); and then to substring lastMsg this is the best i could find

I know you can do this for web, I’m not sure if that applicable to appium. Which xpath you will click after substring?

Hi IIya_G,
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(getDriver());
touchAction.tap(x, y).perform();

Much appreciated for your response.
Thanks

Can you give try below code, i think it would work :-
For Android:-
driver.findElement(MobileBy.AndroidUIAutomator(“new UiSelector().textContains(“Click here”)”)).click();

For iOS:-
driver.findElement(MobileBy.iOSNsPredicateString(“value CONTAINS ‘Click here’”)).click();

Hi,
Do u found solution for this? I am looking for Android and iOs both. Please let me know if u found any thing?