Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 253
Mitul Parekh Avatar asked Sep 10 '18 11:09

Mitul Parekh


3 Answers

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

like image 67
Suban Dhyako Avatar answered Sep 17 '22 15:09

Suban Dhyako


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

like image 31
Christian.D Avatar answered Sep 21 '22 15:09

Christian.D


Use this simple code

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
like image 33
Jatush Lashkari Avatar answered Sep 21 '22 15:09

Jatush Lashkari