How to click a link inside a textview?

Folks,

I have one application in which I have a textview and inside that there’s link called “terms and conditions”. I see there is no any other identifier for clicking on link. Can anyone suggest a way to click on that specific link.?

Attaching the screenshot and the hierarchy for your ready reference.

The textview is clickable. If you click on that element, you will have clicked the link.

1 Like

My test is getting passed. Meaning that it clicks on text, and T&C page doesn’t open. That means I can click on textview but can’t click on link.

Here is the piece of code.

driver.scrollTo(“the Terms and Conditions”);
System.out.println(driver.findElement(tnc).getText());
driver.findElement(tnc).click();

Here is the console output

I have read and agree to the Terms and Conditions
PASSED: launch

Hey, did you find a way to click on that element inside TextView?

No I didn’t. The work-around is to take some position based on percentage and then click on the element. That solved my problem somehow but it doesn’t work throughout the devices.

How I did: found coordinates of that element and then using location you find that link. In my case it was very easy because link located always on the right side of that element(tested on big and small devices and it worked fine)

Hi,

Can you please help me in sharing the line of code in clicking link in textview (like syntax or the method to click link text in textview)

Please help me in resolving this issue.

Thanks in advance
Mani.V

Enjoy. Let me know if you have questions:

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

2 Likes

Hey @Ilya_G, thanks for the solution. It worked pretty well. Bad, it didn’t click in my head previously. :slight_smile:

Thanks a lot!:slight_smile:

Hi,

Can you please share your code. For me its not clicking.

Please help me.

My code

WebElement element = driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextView[1]"));

           Point point = element.getLocation();

           System.out.println(point);

           int x = point.x +1;

           int y = point.y + element.getSize().getHeight() - 1;

           System.out.println("Going to click");

           new TouchAction(driver).tap(x, y).perform();

           System.out.println("Clicked for first time");

           new TouchAction(driver).tap(x, y).perform();

           System.out.println("Clicked for second time");

           new TouchAction(driver).tap(x, y).perform();

           System.out.println("Clicked for third time");

Thanks in advance.

What error does it give?

HI Mashkurm,

Its not giving any error. The output I’m getting is

(35, 281)

Going to click

Clicked for first time

Clicked for second time

Clicked for third time

PASSED: deviceCapabilities

PASSED: mobileFunctionality

Please help me.

Thanks in advance

@sairaghava12345 - May be due to your device size. Please check whether the element is located on the same point (35,281)?

Hi Ilya_G,
Thanks for your answer. But I can’t able to click on text. Pls check the following xpath code.

WebElement el=driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATextView[1]"));

Thanks in advance

Hi @Ilya_G, I got your idea, could you please explain your code because I have many pages in native app, which requires to find link and click. so main part which I don’t understand is point.x + 1 and same with int y where you did -1. why do we have to do +1 and -1?

Thanks in advance.

Hi Greatman,
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