its Xamarin and using if else is causing errors.I tried below but it gave me many issues that else can't start a line and other issues. It could be there is a better way to do this but everything I have tried is an issue. Will this work for both Android and IoS I googled this and went to xamarin docs but its not answered easily.
if( app.Query(x => x.Id("button2").Invoke("exists","button2")));
{ app.Tap("button2");
} {}
else {
app.WaitForElement(x => x.Id("contentPanel"), timeout: TimeSpan.FromSeconds(120));
You could try assigning the Xamarin query to a variable instead of invoking that 'exisits' method. Try the following:
var okButton = app.Query(x => x.Id("button2")).SingleOrDefault();
if(okButton != null)
{
app.Tap(x => x.Id("button2"))
}
else
{
app.WaitForElement(x => x.Id("contentPanel"), timeout: TimeSpan.FromSeconds(120));
}