How can I click on Text link inside in textview in appium
Asked Answered
R

3

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

Ranson answered 10/9, 2018 at 11:2 Comment(9)
can you try the answer once from here : #36497986Pairoar
driver.findElement(By.Xpath("//*[contains(text(), 'REGISTER')]").click();Montague
Not Work @AmitJainRanson
Not Work @PairoarRanson
have you tried using explicit screen coordinates ? It isn't a very elegant way, but It will workAutostability
@rusito explicit screen coordinates is fine but i can't run same test case in other phone.Ranson
@MitulParekh maybe using partial coords ? here is a link i found discuss.appium.io/t/…Autostability
Sorry @rusito23, it's still not workingRanson
@MitulParekh - is it possible to share the name of your app I want to try it at my end ??? I will download app from playstoreMontague
C
3
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

Cranwell answered 11/9, 2018 at 5:31 Comment(3)
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.Cranwell
element boundary coordinates is fine but i can't run same test case in other phoneRanson
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.Cranwell
H
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 ;)

Hulky answered 30/8, 2019 at 7:24 Comment(0)
C
1

Use this simple code

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Cornflower answered 10/10, 2019 at 8:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.