8

How can I click on Text link inside in textview in appium

for ex. i have a string and Don't Have an Account? Register

Only Register has a link other text are disable, when i click on Register it navigate to Register screen.

But I can't click on Register.

Refer a image enter image description here

Suban Dhyako
  • 1,970
  • 1
  • 11
  • 30
Mitul Parekh
  • 151
  • 6

3 Answers3

1
WebElement element = driver.findElement(By.id("element id here"));
Point point = element.getLocation();

//you can change follwing point based on your link location
int x = point.x +1;  
int y = point.y + element.getSize().getHeight() - 1;

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

I find this solution here in appium discussion

Suban Dhyako
  • 1,970
  • 1
  • 11
  • 30
  • try to change the value of x and y using x=point.x+20; or try to inspect using uiAutomatorViewer to know your element boundary and use the relative value of x and y to that element. – Suban Dhyako Sep 11 '18 at 07:39
  • element boundary coordinates is fine but i can't run same test case in other phone – Mitul Parekh Sep 12 '18 at 05:29
  • Does that code work on your device? If that codes run in your device, you can check it on small screen device and large end device and write generic code to support all device. – Suban Dhyako Sep 12 '18 at 05:57
1

I usually try to avoid XPATH in my tests, hence to search for Elements by Text I am doing something like this, which will return a By element to be used in the webdriver interaction.

public static By byText(final String text)
{
    switch (Configuration.getInstance().getPlatform())
    {
        case ANDROID:
            // This requires a UiAutomator2 test driver:
            return MobileBy.AndroidUIAutomator("new UiSelector().text(\"" + text + "\")");
        case IOS:
        default:
            throw new RuntimeException("not implemented");
    }
}

Unfortunately I don't know the equivalent to iOS just now, but it should also be possible somehow ;)

Christian.D
  • 739
  • 1
  • 8
  • 19
1

Use this simple code

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);