Not able to set text in any android mobile app in cloud agent Browserstack

Hi Team,

I am trying to do automation around uber app using automation tool written in C# and tried to set text in one of its fields. unfortunately, I am not able to perform this operation and tried to set the text in other android app like LinkedIn and amazon too, there also I am not able to perform this operation.

In contrast with, we are using similar code to set text for other cloud agent like Saucelab, there I am able to perform this operation successfully.

As i debugged my code, i found an exception in line executor.Driver.SwitchTo().ActiveElement(); under the function TrySwitchToActiveElement()

below is my code.

protected override bool Execute(TExecutor executor)
{
#region execution
var element = executor.TryGetElementFromCache(elementId)?.AppiumElement;

if (element != null)
{
    if (options.NeedTapBefore)
    {
        if (TryTapAndSwitchToActiveElement(executor, ref element) == false)
        {
            return TrySetTextUsingKeyboard(executor);
        }
    }

    if (TrySetTextToElement(executor, element) == false)
    {
        return TrySetTextUsingKeyboard(executor);
    }
    else
	{
        return true;
	}
}
#endregion execution

#region recording
if (TrySwitchToActiveElement(executor, ref element))
{
    return TrySetTextToElement(executor, element);
}
else if (options.NeedTapBefore)
{
    return TrySetTextUsingKeyboard(executor);
}
#endregion recording

return false;

}

private bool TryTapAndSwitchToActiveElement(TExecutor executor, ref IWebElement element)
{
if (TryTapElement(executor, element))
{
return TrySwitchToActiveElement(executor, ref element);
}

return false;

}

private bool TryTapElement(TExecutor executor, IWebElement element)
{
try
{
element.Click();

    return true;
}
catch (Exception ex)
{
    executor.Log.Error(ex);

    return false;
}

}

private bool TrySwitchToActiveElement(TExecutor executor, ref IWebElement element)
{
try
{
element = executor.Driver.SwitchTo().ActiveElement();

    return true;
}
catch (NoSuchElementException ex)
{
    executor.Log.Error(ex, $"There is no active mobile element to set text");
}
catch (Exception ex)
{
    executor.Log.Error(ex);
}

return false;

}

kindly assist me

@Aleksei could you please assist me on this ?

Make it more simple - just tap on element input and send text or type with keayboard.

let me try this and let you know the result

with respect to below function, in case of IOS , It is returning false but in case of android, it is throwing exception and due to that my whole code stops working.

Any other alternative in android to find active element or any other suggestion ?

private bool TrySwitchToActiveElement(TExecutor executor, ref IWebElement element)
{
try
{
element = executor.Driver.SwitchTo().ActiveElement();

    return true;
}
catch (NoSuchElementException ex)
{
    executor.Log.Error(ex, $"There is no active mobile element to set text");
}
catch (Exception ex)
{
    executor.Log.Error(ex);
}

return false;

}

Hi @Aleksei , @wreed

I tried to perform this suggestion and with respect to that i am able to type text but enter does not work after typing the text and screen got stucked for some time. This issue i am facing while using browserstack as cloud agent . the same code base is working fine for other cloud agents.

Kindly assist.
Thank you

This is a job for Browserstack support:

1 Like