Not able to enter text in an textfield in Xamarin UiTest using Android Phone

Viewed 935

I am using Xamarin UiTest for Automating my android application.When i run the test the splash screen loads up in the device and uitest will wait for locating an element but it is failing after waiting for 60 sec.I tried locating using xpath and Id but it is not locating the element

I tried locating using xpath,marked and Id but it is not locating the element.The element has a id associated with it-txtusername.I am using Honor device for running this test.

Actually the login screen is a webview.Please click the image for more details

[Test] public void FirstTest() { app.WaitForElement(c => c.Marked("txtusername"), timeout: TimeSpan.FromSeconds(60)); app.EnterText(c => c.Id("txtusername"),"abc"); app.DismissKeyboard(); }

Code for initializing the app

public class AppInitializer { public static IApp StartApp(Platform platform) { if (platform == Platform.Android) { return ConfigureApp .Android //.InstalledApp("TRL.Software.IMAAPMobile") .ApkFile(@"C:Xamarin.UITest-master\Xamarin.UITest-master\CrossPlatformTest\ik.apk") .DeviceSerial("CYG3Y18809026095") .PreferIdeSettings() .StartApp(); } return ConfigureApp .iOS .StartApp(); } }

Any help is appreciated

1 Answers

According to the official documentation, there are two methods you can use to access information in web views, the CSS and XPath. Here's an example on how to use it in your case:

app.WaitForElement(c => c.WebView().Css("#txtusername"));

and then you can also enter text

  app.ScrollDownTo(c => c.Css("input#txtusername"), "webView1", ScrollStrategy.Gesture);
  app.EnterText(c => c.Css("input#txtusername"), "Chimpanzee");
Related